Solved

test program problem

Posted on 2002-05-08
3
223 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 100 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
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 basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…

749 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