Results 1 to 4 of 4
  1. #1
    Marcus is offline Member
    Join Date
    Jun 2007
    Posts
    92
    Rep Power
    0

    Default Help me with this algorithm

    Hello. I can't access ANY methods in the program from the main.

    Im trying to access the method "count" from:

    Java Code:
     import java.io.*;
     /**
      *
      * @author pag
      */
     public class PriorityQueue implements OrderedQueue {
         
     
         /** Creates a new instance of PriorityQueue */
         public PriorityQueue() {
         }
     
         public void addInOrder(Object thisObj) {
         }
     
         public Item remove() {
             Item x;
             x = new Item();
             return x;
         }
     
         public PriorityLinkedListIterator iterator() {
             PriorityLinkedListIterator x;
             x = new PriorityLinkedListIterator();
             return x;
         }
     
         public int count() {
             int x = 0;
              return x;
         }
     
     }
    main:
    Java Code:
     import java.io.*;
     
     
     /**
      *
      * @author pag
      */
     public class Main {
         
         /** Creates a new instance of Main */
         public Main() {
         }
         
         /**
          * @param args the command line arguments
          */
         public static void main(String[] args) {
             // TODO code application logic here
             new PriorityQueue();
             System.out.println(PriorityQueue.count());
             clearscreen();
             menu();
         }
         
         static void menu(){
         //display main menu
             System.out.println("Main Menu");
             System.out.println("1. Print messages from file");
             System.out.println("2. Place messages in priority queue");
             System.out.println("3. Display next item in queue");
             System.out.println("4. Print messages in priority order");
             System.out.println("5. Display number of items in queue");
             System.out.println("6. Write remaining contents to file");   
         }
         
         static void clearscreen(){
             for (int i = 0; i < 24; i++){
                         System.out.println();
             }
             
         }
     
     }
    The "System.out.println(PriorityQueue.count)" Dosen't work. The only option netbeans gives me with this class (or any class) is "PriorityQueue.Class"
    Help me!

    Marcus:cool:

  2. #2
    Eric is offline Senior Member
    Join Date
    Jun 2007
    Posts
    111
    Rep Power
    0

    Default

    That won't compile i think you are looking for System.out.println()..

    Greetings

    Eric

  3. #3
    Daniel is offline Member
    Join Date
    Jun 2007
    Posts
    91
    Rep Power
    0

    Default

    I'm sure you meant PriorityQueue.count()

    The problem its throwing is that i can't reference a non-static method in a static way.

    Greetings.

    Daniel:o

  4. #4
    olatunbode is offline Member
    Join Date
    Jul 2007
    Posts
    5
    Rep Power
    0

    Smile Little Error

    Hi,

    You cant call a non-static method by using Classname.Methodname format. You have to first create an object of the Class first, then use that object to call the methd. For instance:

    PriorityQueue x = new PriorityQueue();
    x.count();

    or use a faster approach...
    new PriorityQueue().count();

    any of these should work.

    Take care!

    Jide

Similar Threads

  1. Modify A* Algorithm
    By prakharbirla in forum Advanced Java
    Replies: 1
    Last Post: 02-13-2008, 07:25 PM
  2. Help with making this algorithm better
    By RLRExtra in forum New To Java
    Replies: 6
    Last Post: 01-17-2008, 05:11 PM
  3. Help with sort algorithm
    By zoe in forum New To Java
    Replies: 1
    Last Post: 08-07-2007, 07:09 AM
  4. Help with algorithm
    By susan in forum New To Java
    Replies: 1
    Last Post: 07-13-2007, 11:26 PM
  5. Help with Algorithm
    By Daniel in forum Advanced Java
    Replies: 2
    Last Post: 07-02-2007, 06:51 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •