This is from the book Head First Java 2nd Edition. The book suggests(?) I use: jave GameLauncher.java to run it. Compiling gives me errors about an unresolved symbol on the three lines with guessp# = p#.number; reffering to the . just before number... Any ideas?
[ February 27, 2005: Message edited by: Michael Baca ] [ February 27, 2005: Message edited by: Michael Baca ]
In the listing you have for the Player class, number is a local variable in guess() - it doesn't have any field called 'number', so p1.number isn't valid.
With a public field (not good practice) number, things might work better.
[ February 27, 2005: Message edited by: Horatio Westock ]
Joined: May 27, 2004
Well it compiled that time, and it sort of works. The number guessed even if correct does not end the game. But either way it's not a big deal. I guess the author made a mistake in the code. I sure hope the rest of the code in this book works..
Thanks for the help. Btw, what exactly would be 'good practice' in a case such as this one? I thought just making a class public made it accessible to any other class in my program. [ February 27, 2005: Message edited by: Michael Baca ]
Joined: Feb 23, 2005
I'd probably have the field private, and have accessor methods:
This way, only the object itself can modify it's state. If later, you want to do something special with the field, you can maintain the same accessor methods, so other classes which use it don't have to be changed.
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com