test program problem

Posted on 2002-05-08
Last Modified: 2010-03-31
Question by:penfold69

Author Comment

ID: 6997175
i have a problem with my test program, their seems to be an error in it! 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("     Printer Queue System       ");
          System.out.println("                                ");
          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)");
     public static void main (String [] arguments)
          Queue test = new Queue();
          int choice;
          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();
                                     System.out.println("Enter in the Document Name?");
                                     DocumentName = uuInOut.ReadString();
                                     System.out.println("Enter in the Owner?");
                                     Owner = uuInOut.ReadInt();
                    case 2 :       user.remove();
                                   System.out.println("Document Printed!");
                   case 3 :    user.displayAll();                                              
                    case 4 :     user.purgequeue();          
                    case 5 :    System.out.println("Feaure NOT added!");
                    case 6 :     System.out.println("All contents of Queue Displayed below!");
                    case 7 :     System.out.println("Size of queue feature NOT added!");
                    default:     System.out.println("Error!, Please select 1 to 8 only!");
               System.out.println("\n Enter your choice?");
               choice = uuInOut.ReadInt();    
LVL 35

Expert Comment

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.

Accepted Solution

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.

Featured Post

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

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

Suggested Solutions

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
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 …
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

773 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