badrul hisham
cannot find symbol class array queue--plzz somebody help..
1 Answer(s)      5 years and 2 months ago
Posted in : Java Beginners

import java.util.*;

public class Test {

public static void main(String[] args) { ArrayQueue<String> q = new ArrayQueue<String>(6);

System.out.println("A new queue is an empty queue ... " + q.isEmpty());
System.out.println("Adding six strings to the queue ...");
System.out.println("A: " + q.join(new String("A")));
System.out.println("B: " + q.join(new String("B")));
System.out.println("C: " + q.join(new String("C")));
System.out.println("D: " + q.join(new String("D")));

System.out.println("A: " + q.leave(new String("A")));
System.out.println("B: " + q.leave(new String("B")));
System.out.println("C: " + q.leave(new String("C")));

System.out.println("E: " + q.join(new String("E")));
System.out.println("F: " + q.join(new String("F")));
System.out.println("G: " + q.join(new String("G")));
System.out.println("H: " + q.join(new String("H")));
System.out.println("I: " + q.join(new String("I")));

System.out.println("G: " + q.leave(new String("G")));
System.out.println("H: " + q.leave(new String("H")));
System.out.println("I: " + q.leave(new String("I")));

System.out.println("The queue is now full ..." + q.isFull());
System.out.println("Adding a string to a full queue ...");
System.out.println("tagore: " + q.join(new String("tagore")));
System.out.println("Emptying the queue item by item ...");

while (!q.isEmpty()) {
System.out.println(q.retrieve());
q.leave();

} } }

Ads

View Answers

October 10, 2011 at 11:56 AM


The package java.util.* does not contain the class ArrayQueue. It is found in another package. Either you import that package through the jar file or implement the class ArrayQueue.

ArrayQueue.java:

class ArrayQueue implements Queue 
{

    static final int defaultsize = 100;

    Object data[];
    int head;
    int tail;
    int size;

    ArrayQueue(int maxsize) 
    {
        data = new Object[maxsize];
        head = 0;
        tail = 0;
        size = maxsize;
    }

    ArrayQueue() 
    {
        data = new Object[defaultsize];
        head = 0;
        tail = 0;
        size = defaultsize;
    }

    public void enqueue(Object elem) 
    {
    Assert.notFalse((tail+1)%size != head, "Queue Full");
    data[tail] = elem;
    tail = (tail + 1) % size;
    }

    public Object dequeue() 
    {
    Object retval;

    if (head == tail)
        return null;
    retval = data[head];
    head = (head + 1) % size;
    return retval;
    }

    public boolean empty() 
    {
    return head == tail;
    }

    public String toString()
    {
    String result = "[";
        int tmpHead = head;
    if (tmpHead != tail)
    {
            result = result + data[tmpHead];
            tmpHead = (tmpHead + 1) % size;
            while (tmpHead != tail)
            {
        result = result + "," + data[tmpHead];
                tmpHead = (tmpHead + 1) % size;
        }
    }
    result = result + "]";
    return result;
    }

}









Related Tutorials/Questions & Answers:
cannot find symbol class array queue--plzz somebody help..
cannot find symbol class array queue--plzz somebody help..  import java.util.*; public class Test { public static void main(String[] args.... ArrayQueue.java: class ArrayQueue implements Queue { static final int defaultsize
Java error cannot find symbol
the java error cannot find symbol. In this example a class name 'cannot find... “cannot find symbol”. The reason behind cannot find symbol error.../src/ Cannotfindsymbol.java:11: cannot find symbol symbol: variable z
Advertisements
cannot find symbol method nextchar()??
cannot find symbol method nextchar()??  import java.util.Scanner; public class Calc5{ public static void main(String args[]){ Scanner... } // end of class
Java error cannot find symbol
symbol. For this we have a class name 'cannot find symbol'. Inside the main... Java error cannot find symbol       The java error cannot find symbol
cannot find symbol - Java Beginners
cannot find symbol  public class Areatest { public static void main(String[]args) { Figure[]figures={new Triangle(2.0,3.0,3.0),new Rectangle(4.0,6.0),new Square(5.0)}; for(int i=0;i
Java error cannot find symbol
illustrates what is cannot find symbol : public class CannotFindSymbol...Java error cannot find symbol In this section you will learn about "cannot find symbol" in java. Java cannot find symbol is a type of error occurs
JSP cannot find symbol error - JSP-Servlet
JSP cannot find symbol error  Suppose-- we created 'a.jsp' in which we make a database connection... how to retrieve 'new' here... If I want to access the 'new' string within the form what should i do???  
cannot find symbol Scanner sc = new Scanner(system.in)
cannot find symbol Scanner sc = new Scanner(system.in)  In my one of the program in getting the error: cannot find symbol Scanner sc = new Scanner(system.in) How to resolve the error: cannot find symbol Scanner sc = new Scanner
Cannot find tag library descriptor
Cannot find tag library descriptor  Cannot find tag library descriptor...? How to resolve in struts in eclipse
System.out.println cannot be written inside a class
System.out.println cannot be written inside a class  why System.out.println cannot be written inside a class
please please i wanna insertion sort program find calendar to array value (1000,5000,10000), please help me
Insertion sort program find calendar to array value 1000,5000,10000  program find calendar for insertion sort in jfram to array 1000
HELP WITH ARRAY
HELP WITH ARRAY  Hi i would like this program: public class ArrayApp... ([]) it should find the number and print it "Found (number)" pls. help me...) System.out.println("Can't find" + searchId); else System.out.print("Found
error cannot access class com.opensymphony.xwork2.ActionContext, wrong version
error cannot access class com.opensymphony.xwork2.ActionContext, wrong version  Error(1,32): cannot access class com.opensymphony.xwork2.ActionContext; class file has wrong version 49.0, should be 45.3 or 46.0 or 47.0 or 48.0
cannot find java.exe error while opening netbean5.5 - IDE Questions
cannot find java.exe error while opening netbean5.5  HI, 1)i am working netbean5.5 tool.I got the error of cannot find c:\programfiles\java... solve this error , plz help me Regards Gokul
Help With an Array
Help With an Array  So what Im trying to do is write an array declaration to represent students names for a class and homework grades for each student. I have included my arrays for a declaration for 25 students names in a class
Cannot find FacesContext exception - Java Server Faces Questions
Cannot find FacesContext exception  Hi all, I am into an web application,where we are using Richfaces. Now, When I try to create a new Jsp page using taglibs[faces, html], getting 'Cannot find FacesContext' exception. What
Help With an Array
Help With an Array  // ******************** // Sales.java // // Reads.... // // ******************** import java.util.Scanner; public class Sales { public static void main(String... need help from this part on. I need that part corrected and add a portion
Help
\SlideImageMIDlet.java:36: cannot find symbol symbol : class SlideMenu location...\2.5.2\apps\SlideImageMIDlet\src\SlideImageMIDlet.java:20: cannot find symbol symbol : class SlideMenu location: class IconsCanvas SlideMenu menu = null; ^ C
javax.servlet.jsp.JspException: Cannot find FacesContext - Java Server Faces Questions
javax.servlet.jsp.JspException: Cannot find FacesContext  exception javax.servlet.ServletException: Cannot find FacesContext...(HttpServlet.java:802) root cause javax.servlet.jsp.JspException: Cannot find
array find all possible dimension
array find all possible dimension  Given array: int[] dimension = { 1, 2, 3 }; That produces the output: 1 2 3 12 13 23 123 I'm new to array...i... if someone could help...thanks
Find out last character of array
Find out last character of array  How we can find out the last character of array in java program
Error : javax.servlet.jsp.JspException: Cannot find bean org.apache.struts.taglib.html.BEAN in any scope
Error : javax.servlet.jsp.JspException: Cannot find bean org.apache.struts.taglib.html.BEAN in any scope  I am getting following error in my struts... javax.servlet.jsp.JspException: Cannot find bean org.apache.struts.taglib.html.BEAN
Find position of an array element
Find position of an array element In this section, you will learn how to find the index of an array element. For this, we have allowed the user to enter the array elements of their choice and also the number whose index value
plz help me find a program
plz help me find a program  plz help..i want a source code in jsp for order processing
Currency Symbol problem
Currency Symbol problem  Hi All, My Server side code... to show this like RM 12345. How to solve this? Any help or idea is greatly..., The java.util.Locale class defines the available local: Locale.CANADA Locale.CANADA_FRENCH
Netbeans Array help
of rolls possible within the array Help plese!   Hi Friend, Try...Netbeans Array help  Ok here is my code- * * To change this template... java.util.Random; /** * */ public class ContinueRollDie { * @param args
Find a missing element from array
Find a missing element from array We have two arrays A and B where B consists... the array B. From these two arrays, we have to find the missing element from the second array i.e from B. For this, we have calculated the sum of elements from both
To find first two maximum numbers in an array
To find first two maximum numbers in an array  Java program to find first two maximum numbers in an array,using single loop without sorting array
could not find a getter for id in contact class
could not find a getter for id in contact class   could not find a getter for id in contact class
USE ARRAY TO FIND THE LARGEST NUMBER AND OCCURRENCE
USE ARRAY TO FIND THE LARGEST NUMBER AND OCCURRENCE  i have some exercise from my lecturer and I still can't understand about ARRAY. here it is: write a program that reads 10 numbers from the keyboard. find the largest number
Difference between abstract class and an interface
now a days in core java. This section will help you to find the differences... will find the difference as follows : First difference, an abstract class... an abstract class is class which cannot extends multiple classes because java