Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Using Queue, cannot find symbol method enqueue

  1. #1
    Junior Member
    Join Date
    Jul 2011
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Using Queue, cannot find symbol method enqueue

    Hello, I have taken only some programming and am just beginning to really learn some little more advanced Java. When I was programming this I took some code I was supplied with and modified it.

    The only problem I am really having is that I cannot figure out why my enqueue() method won't accept string arrays and why the NewArray() method is not found. Can anybody help me?

    Here is my code:

    ListQueue.java

    // ListQueue class
    //
    // CONSTRUCTION: with no initializer
    //
    // ******************PUBLIC OPERATIONS*********************
    // void enqueue( x ) --> Insert x
    // String[] getFront( ) --> Return least recently inserted item
    // String[] dequeue( ) --> Return and remove least recent item
    // boolean isEmpty( ) --> Return true if empty; else false
    // void makeEmpty( ) --> Remove all items
    // ******************ERRORS************************** ******
    // getFront or dequeue on empty queue

    /**
    * List-based implementation of the queue.
    */

    import java.util.Arrays;
    import java.io.*;
    import java.util.Scanner;
    import java.lang.Object;

    public class ListQueue implements QueueInterface{

    /**
    * Construct the queue.
    */
    public ListQueue( ) {
    front = back = null;
    }

    /**
    * Test if the queue is logically empty.
    * @return true if empty, false otherwise.
    */
    public boolean isEmpty( ) {
    return front == null;
    }

    /**
    * Insert a new item into the queue.
    * @param x the item to insert.
    */
    public void Enqueue( String[] x ) {
    if( isEmpty( ) ) // Make queue of one element
    back = front = new ListNode( x );
    else // Regular case
    back = back.next = new ListNode( x );
    }

    /**
    * Return and remove the least recently inserted item
    * from the queue.
    * @return the least recently inserted item in the queue.
    * @throws UnderflowException if the queue is empty.
    */
    public String[] dequeue( ) {
    if( isEmpty( ) )
    throw new UnderflowException( "ListQueue dequeue" );

    String[] returnValue = front.element;
    front = front.next;
    return returnValue;
    }

    /**
    * Get the least recently inserted item in the queue.
    * Does not alter the queue.
    * @return the least recently inserted item in the queue.
    * @throws UnderflowException if the queue is empty.
    */
    public String[] getFront( ) {
    if( isEmpty( ) )
    throw new UnderflowException( "ListQueue getFront" );
    return front.element;
    }

    /**
    * Make the queue logically empty.
    */
    public void makeEmpty( ) {
    front = null;
    back = null;
    }



    private ListNode front;
    private ListNode back;

    //New stuff
    class NewArray{

    String [] arr;

    public String [] NewArray() {
    arr = new String [10];
    fill();
    return arr;
    }

    public void sort(){
    Arrays.sort(arr);
    }

    public void fill(){
    for(int i=0; i<=10; i++){
    arr[i] = ReadThread(); // have program read words from file eventually
    // arr[i] = names.next(); ?
    }

    }

    public String ReadThread(){
    String dummy = "missing";
    try{
    File numbersFile = new File("numbers.txt");
    File namesFile = new File("names.txt");
    Scanner numbers = new Scanner(numbersFile);
    Scanner names = new Scanner(namesFile);
    dummy = names.next();
    }
    catch(FileNotFoundException e){
    System.out.println("Not Found");
    }
    return dummy;
    }


    }
    }

    /**
    * Exception class for access in empty containers
    * such as stacks, queues, and priority queues.
    */


    class ListNode {
    // Constructors
    public ListNode( String[] theElement ) {
    this( theElement, null );
    }

    public ListNode( String[] theElement, ListNode n ) {
    element = theElement;
    next = n;
    }

    public String[] element;
    public ListNode next;
    }


    QueueInterface.java


    // Queue interface
    //
    // ******************PUBLIC OPERATIONS*********************
    // void enqueue( x ) --> Insert x
    // Object getFront( ) --> Return least recently inserted item
    // Object dequeue( ) --> Return and remove least recent item
    // boolean isEmpty( ) --> Return true if empty; else false
    // void makeEmpty( ) --> Remove all items
    // ******************ERRORS************************** ******
    // getFront or dequeue on empty queue

    /**
    * Protocol for queues.
    * @author Mark Allen Weiss
    */
    public interface QueueInterface {
    /**
    * Insert a new item into the queue.
    * @param x the item to insert.
    */
    void Enqueue( String[] x );

    /**
    * Get the least recently inserted item in the queue.
    * Does not alter the queue.
    * @return the least recently inserted item in the queue.
    * @exception UnderflowException if the queue is empty.
    */
    String[] getFront( );

    /**
    * Return and remove the least recently inserted item
    * from the queue.
    * @return the least recently inserted item in the queue.
    * @exception UnderflowException if the queue is empty.
    */
    String[] dequeue( );

    /**
    * Test if the queue is logically empty.
    * @return true if empty, false otherwise.
    */
    boolean isEmpty( );

    /**
    * Make the queue logically empty.
    */
    void makeEmpty( );
    }


    TestQueue.java

    import java.lang.Object;

    public class TestQueue{

    public static void main(String [] args){

    //Add code here to start threads
    String [] arrayname = new String [10];
    ListQueue queue = new ListQueue();
    Enqueue(arrayname);
    arrayname = NewArray();
    Enqueue(NewArray());
    Enqueue(arrayname);

    }
    }

    UnderflowException.java

    public class UnderflowException extends RuntimeException {
    /**
    * Construct this exception object.
    * @param message the error message.
    */
    public UnderflowException( String message ) {
    super( message );
    }
    }


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Using Queue, cannot find symbol method enqueue

    hy my enqueue() method won't accept string arrays and why the NewArray() method is not found.
    Do you get an error message ? Please copy and paste the full text here.

    Please wrap your posted code in code tags to preserve its formatting. See: BB Code List - Java Forums

    Java naming conventions: Class names begin with uppercase, methods and variables with lowercase

    public String [] NewArray() {
    vs
    public String [] newArray() {

  3. #3
    Junior Member
    Join Date
    Jul 2011
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Using Queue, cannot find symbol method enqueue

    Quote Originally Posted by Norm View Post
    Do you get an error message ? Please copy and paste the full text here.

    Please wrap your posted code in code tags to preserve its formatting. See: BB Code List - Java Forums

    Java naming conventions: Class names begin with uppercase, methods and variables with lowercase

    public String [] NewArray() {
    vs
    public String [] newArray() {


    Thank you, the problem that I found in my main was that I was not calling the instantiated object followed by the method.
    example:
    Object is of type Queue, named q1
    Method is enqueue()

    my code read:
    enqueue(Something);

    while it should have been:
    q1.enqueue(Something);

    Forgetting the created object caused the "cannot find symbol method" error, because enqueue belongs to Queue and not my main method.

    Thanks anyways

Similar Threads

  1. Cannot find Symbol?
    By defmetalhead in forum What's Wrong With My Code?
    Replies: 8
    Last Post: July 5th, 2011, 08:48 AM
  2. Cannot find symbol error
    By AnuR in forum What's Wrong With My Code?
    Replies: 9
    Last Post: February 23rd, 2011, 02:50 PM
  3. Cannot find symbol?
    By stealthmonkey in forum What's Wrong With My Code?
    Replies: 3
    Last Post: December 10th, 2010, 10:02 PM
  4. Why the compiler can not find the symbol?
    By AlicNewbie in forum What's Wrong With My Code?
    Replies: 1
    Last Post: February 16th, 2010, 08:16 PM
  5. cannot find symbol - method
    By kyuss in forum Object Oriented Programming
    Replies: 2
    Last Post: December 7th, 2009, 01:01 PM

Tags for this Thread