?
Solved

test program problem

Posted on 2002-05-08
3
Medium Priority
?
228 Views
Last Modified: 2010-03-31
0
Comment
Question by:penfold69
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 

Author Comment

by:penfold69
ID: 6997175
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();    
          }
     }
}
0
 
LVL 35

Expert Comment

by:girionis
ID: 6997230
 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.
0
 
LVL 2

Accepted Solution

by:
triso earned 400 total points
ID: 6997247
You will have to create a QueueNode object before you can use it.  Right under your line "Queue test = new Queue();" in main(), you can put "QueueNode node = new QueueNode();"

Then you will have to change "Position" to "node.Position" for each of those data members.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Suggested Courses
Course of the Month14 days, 4 hours left to enroll

801 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question