Link to home
Start Free TrialLog in
Avatar of penfold69
penfold69

asked on

test program problem

Avatar of penfold69
penfold69

ASKER

i have a problem with my test program, their seems to be an error in it!

TestQueue.java:39: Can't make a static reference to nonstatic variable Position in class QueueNode.

                                   Position = uuInOut.ReadInt();


some variables are declared in the class below
class QueueNode
{

     public int Position;
     public String DocumentName;
     public String Owner;
     public int Size;
     
     public QueueNode next;
     public QueueNode previous;
     
}


import uuInOut;
class TestQueue extends Queue
{
     static void displayMenu()
     {
          System.out.println("--------------------------------");
          System.out.println("     Printer Queue System       ");
          System.out.println("--------------------------------");
          System.out.println("                                ");
          System.out.println("Option\tAction");
          System.out.println("   ");
          System.out.println("1\tAdd document");
          System.out.println("2\tPrint a Document");
          System.out.println("3\tDisplay Contents of Queue");
          System.out.println("    ");
          System.out.println("4\tPurge the queue");
          System.out.println("5\tRemove a Document");
          System.out.println("6\tDisplay how many documents in the Queue");
          System.out.println("7\tDisplay the Size of Queue (KB)");
          System.out.println("8\tExit");
         
     }
     
     public static void main (String [] arguments)
     {
          Queue test = new Queue();
         
          int choice;
         
          displayMenu();
          System.out.println("\n Enter your choice?");
          choice = uuInOut.ReadInt();
         
          while (choice !=8)
          {
               switch (choice)
               {
                    case 1 :       System.out.println("Enter in the Job Position?");
                                   Position = uuInOut.ReadInt();
                                   test.add(Position);
                                     System.out.println("Enter in the Document Name?");
                                     DocumentName = uuInOut.ReadString();
                                   test.add(DocumentName);
                                     System.out.println("Enter in the Owner?");
                                     Owner = uuInOut.ReadInt();
                                   test.add(Owner);
                                    break;
                               
                    case 2 :       user.remove();
                                   System.out.println("Document Printed!");
                                   break;
                                   
                   case 3 :    user.displayAll();                                              
                                   break;
                                   
                    case 4 :     user.purgequeue();          
                                   break;
                                   
                    case 5 :    System.out.println("Feaure NOT added!");
                                   break;
                                   
                    case 6 :     System.out.println("All contents of Queue Displayed below!");
                                   user.getDocumentCount();
                                   break;
                                   
                    case 7 :     System.out.println("Size of queue feature NOT added!");
                                   break;
                                   
                    default:     System.out.println("Error!, Please select 1 to 8 only!");
                                   
               }
               
               displayMenu();
               System.out.println("\n Enter your choice?");
               choice = uuInOut.ReadInt();    
          }
     }
}
Avatar of girionis
 Either create an instance of the class QueueNode like: QueueNode qn = new QueueNode() and access the "Position" variable through the "qn" variable like: qn.Position  = uuInOut.ReadInt(); or declare your QueueNode class final or the variables in there static.

 Hope it helps.
ASKER CERTIFIED SOLUTION
Avatar of triso
triso

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial