Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-02-2007, 07:15 AM
Member
 
Join Date: Jun 2007
Posts: 92
Marcus is on a distinguished road
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:

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:
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
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 07-02-2007, 07:18 AM
Senior Member
 
Join Date: Jun 2007
Posts: 111
Eric is on a distinguished road
That won't compile i think you are looking for System.out.println()..

Greetings

Eric
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 07-02-2007, 07:22 AM
Member
 
Join Date: Jun 2007
Posts: 92
Daniel is on a distinguished road
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
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 07-02-2007, 02:30 PM
Member
 
Join Date: Jul 2007
Posts: 5
olatunbode is on a distinguished road
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
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Modify A* Algorithm prakharbirla Advanced Java 1 02-13-2008 07:25 PM
Help with making this algorithm better RLRExtra New To Java 6 01-17-2008 05:11 PM
Help with sort algorithm zoe New To Java 1 08-07-2007 07:09 AM
Help with algorithm susan New To Java 1 07-13-2007 11:26 PM
Help with Algorithm Daniel Advanced Java 2 07-02-2007 06:51 AM


All times are GMT +3. The time now is 05:15 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org