Page 1 of 2 12 LastLast
Results 1 to 10 of 14

Thread: Some Java help

  1. #1
    Join Date
    Apr 2005
    Location
    Lancaster, PA
    Beans
    166
    Distro
    Ubuntu Breezy 5.10

    Some Java help

    Hey guys. I'm pretty new to Java but I'm pretty experienced with C++ (in terms of a college student).

    I'm working on the "Dining Philosophers" problem, but I'm having trouble at the very start with compiling. All I want to do right now is create five "philosophers" and then have them print out their pertinent info.

    However, when I compile I get this for each one:
    Code:
    dining.java:3: cannot find symbol
    symbol  : class Dude
    location: class diningDudes
        Dude d1 = new Dude(HUNGRY, "Jerry Garcia", 1);
        ^
    It doesn't give me problems about the other public functions, just the constructor. Any tips on how to get past this?

    I've got my dining.java file wich contains:
    Code:
    class diningDudes {
      public static void main(String[] args) {
        int HUNGRY = 1;
        int EATING = 2;
        int THINKING = 3;
        
        Dude d1 = new Dude(HUNGRY, "Jerry Garcia", 1);
        Dude d2 = new Dude(HUNGRY, "Rick Wakeman", 2);
        Dude d3 = new Dude(HUNGRY, "Jeff Lynne", 3);
        Dude d4 = new Dude(HUNGRY, "Keith Richards", 4);
        Dude d5 = new Dude(HUNGRY, "Keith Emerson", 5);
    	
        d1.start();
        d2.start();
        d3.start();
        d4.start();
        d5.start();
      }
    }
    and I also have my philosophers class (but I'm using dudes instead):
    Code:
    public class Dude extends Thread {
        private int status;
        private string name;
    	private int id;
    	
    	public static int HUNGRY = 1;
    	public static int EATING = 2;
    	public static int THINKING = 3;
    	
    
        public Dude(int stat, string nam, int ident) {
            status = stat;
            name = nam;
        }
        public string getName(){return name;}
        public int getStatus(){return status;}
        public int getID(){return id;}
        
        public void run() {
    		/*for(int i=0;i<meals;i++)
    			{
    				try{
    				m.getForks(this.getmyId());
    				System.out.println("Philosopher "+this.getmyId()+ " is eating!");
    				m.release(this.getmyId());
    				}catch(Exception e){}
    			}*/
    		System.out.println(this.getName()+" is " + this.getStatus() + " and " + this.getID() + "!");	  
    	}
    }

  2. #2
    Join Date
    Apr 2005
    Location
    Sweden
    Beans
    380
    Distro
    Dapper Drake Testing/

    Re: Some Java help

    Ok. First of all, there are three occurances of "string" in the Dude.java file. Changing them to "String" will eliminate a couple of errors.

    Also, method called getName() already exists in java.lang.Thread, so you have to choose a different name for your method since it's final.
    Software Failure. Press left mouse button to continue.
    Guru Meditation #00000000.48454C50

  3. #3
    Join Date
    Apr 2005
    Location
    Lancaster, PA
    Beans
    166
    Distro
    Ubuntu Breezy 5.10

    Re: Some Java help

    Hmm... I actually wasn't getting any trouble from the string/String or getName() issues you mentioned. I changed them like you said and still get the same 10 errors (1 for each instance of Dude).

  4. #4
    Join Date
    Apr 2005
    Location
    Sweden
    Beans
    380
    Distro
    Dapper Drake Testing/

    Re: Some Java help

    Quote Originally Posted by raublekick
    Hmm... I actually wasn't getting any trouble from the string/String or getName() issues you mentioned. I changed them like you said and still get the same 10 errors (1 for each instance of Dude).
    Hm.... Strange. I just tried compiling it, and i got no errors at all (after the modifications suggested above).
    Software Failure. Press left mouse button to continue.
    Guru Meditation #00000000.48454C50

  5. #5
    Join Date
    Apr 2005
    Location
    Lancaster, PA
    Beans
    166
    Distro
    Ubuntu Breezy 5.10

    Re: Some Java help

    Really?

    I guess I should mention that I'm using javac to compile, just to make sure we're both on the same page. Did you run it? Does it print out correctly?


    Thanks for taking the tiem to check this out.

  6. #6
    Join Date
    Apr 2005
    Location
    Sweden
    Beans
    380
    Distro
    Dapper Drake Testing/

    Re: Some Java help

    Quote Originally Posted by raublekick
    Really?

    I guess I should mention that I'm using javac to compile, just to make sure we're both on the same page. Did you run it? Does it print out correctly?


    Thanks for taking the tiem to check this out.
    I'm using javac supplied with jdk1.5.0_06.

    Here is the result:

    Code:
    > javac diningDudes.java
    
    > java diningDudes
    Jerry Garcia is 1 and 0!
    Rick Wakeman is 1 and 0!
    Jeff Lynne is 1 and 0!
    Keith Richards is 1 and 0!
    Keith Emerson is 1 and 0!
    I guess it works (since you have commented out their ability to eat ).
    Software Failure. Press left mouse button to continue.
    Guru Meditation #00000000.48454C50

  7. #7
    Join Date
    Apr 2005
    Location
    Lancaster, PA
    Beans
    166
    Distro
    Ubuntu Breezy 5.10

    Re: Some Java help

    All those zeros should be different though. Apart from that, that's all I really wanted for right now. Like I said, I'm pretty new with Java so I'm taking this one step at a time.

    here is exactly what happens when I compile
    Code:
    andrew@mario:~/phil$ javac dining.java
    dining.java:7: cannot find symbol
    symbol  : class Dude
    location: class diningDudes
        Dude d1 = new Dude(HUNGRY, "Jerry Garcia", 1);
        ^
    dining.java:7: cannot find symbol
    symbol  : class Dude
    location: class diningDudes
        Dude d1 = new Dude(HUNGRY, "Jerry Garcia", 1);
                      ^
    dining.java:8: cannot find symbol
    symbol  : class Dude
    location: class diningDudes
        Dude d2 = new Dude(HUNGRY, "Rick Wakeman", 2);
        ^
    dining.java:8: cannot find symbol
    symbol  : class Dude
    location: class diningDudes
        Dude d2 = new Dude(HUNGRY, "Rick Wakeman", 2);
                      ^
    dining.java:9: cannot find symbol
    symbol  : class Dude
    location: class diningDudes
            Dude d3 = new Dude(HUNGRY, "Jeff Lynne", 3);
            ^
    dining.java:9: cannot find symbol
    symbol  : class Dude
    location: class diningDudes
            Dude d3 = new Dude(HUNGRY, "Jeff Lynne", 3);
                          ^
    dining.java:10: cannot find symbol
    symbol  : class Dude
    location: class diningDudes
            Dude d4 = new Dude(HUNGRY, "Keith Richards", 4);
            ^
    dining.java:10: cannot find symbol
    symbol  : class Dude
    location: class diningDudes
            Dude d4 = new Dude(HUNGRY, "Keith Richards", 4);
                          ^
    dining.java:11: cannot find symbol
    symbol  : class Dude
    location: class diningDudes
            Dude d5 = new Dude(HUNGRY, "Keith Emerson", 5);
            ^
    dining.java:11: cannot find symbol
    symbol  : class Dude
    location: class diningDudes
            Dude d5 = new Dude(HUNGRY, "Keith Emerson", 5);
                          ^
    10 errors
    Last edited by raublekick; December 10th, 2005 at 01:12 AM.

  8. #8
    Join Date
    Apr 2005
    Location
    Sweden
    Beans
    380
    Distro
    Dapper Drake Testing/

    Re: Some Java help

    Quote Originally Posted by raublekick
    All those zeros should be different though. Apart from that, that's all I really wanted for right now. Like I said, I'm pretty new with Java so I'm taking this one step at a time.
    [/code]
    I bet a
    Code:
    id=ident;
    in the constructor will solve your zeros problem
    Software Failure. Press left mouse button to continue.
    Guru Meditation #00000000.48454C50

  9. #9
    Join Date
    Apr 2005
    Location
    Sweden
    Beans
    380
    Distro
    Dapper Drake Testing/

    Re: Some Java help

    Quote Originally Posted by raublekick
    here is exactly what happens when I compile
    Looks to me that it doesn't find the Dude class.

    What happens if you put the two .java files you pasted in the first message in the same (new and fresh) directory, and then compile the diningDudes.java file?

    EDIT: I see that your name of the diningDudes source file is not called diningDudes.java but dining.java. The file name should be the same as the class name. Make sure that the Dude .java file really is called Dude.java. If not, you'll get this error.
    Last edited by Adrian; December 10th, 2005 at 01:26 AM.
    Software Failure. Press left mouse button to continue.
    Guru Meditation #00000000.48454C50

  10. #10
    Join Date
    Apr 2005
    Location
    Lancaster, PA
    Beans
    166
    Distro
    Ubuntu Breezy 5.10

    Re: Some Java help

    Quote Originally Posted by Adrian
    Looks to me that it doesn't find the Dude class.

    What happens if you put the two .java files you pasted in the first message in the same (new and fresh) directory, and then compile the diningDudes.java file?

    Before reading this I took the code I pasted here, made a new directory, and made two new java files and pasted the code in. Got the same errors...

    And the id=ident thing I fixed after I posted the code, but forgot to update hehe

Page 1 of 2 12 LastLast

Bookmarks

Posting Permissions

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