aspose file tools*
The moose likes Beginning Java and the fly likes Head First Java - Having a problem with GuessGame Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Head First Java - Having a problem with GuessGame" Watch "Head First Java - Having a problem with GuessGame" New topic
Author

Head First Java - Having a problem with GuessGame

Luke McAllister
Greenhorn

Joined: Sep 07, 2009
Posts: 5
After having lots of different beginner problems with this particular section that I was able to work out on my own and with the help of this forum. I can't seem to figure this one out when I try to compile GuessGame.java as it is typed in the revision 2 book.


This is the error(s) I get when I try to compile.

*the ^ symbol is supposed to be under the lowercase "p" on my terminal window, not sure if it cut/pastes properly.


javac GuessGame.java
GuessGame.java:39: cannot find symbol
symbol : variable p1isRight
location: class GuessGame
p1isRight = true;
^
GuessGame.java:42: cannot find symbol
symbol : variable p2isRight
location: class GuessGame
p2isRight = true;
^
GuessGame.java:45: cannot find symbol
symbol : variable p3isRight
location: class GuessGame
p3isRight = true;
^
GuessGame.java:48: cannot find symbol
symbol : variable p1isRight
location: class GuessGame
if (p1isRight || p2isRight || p3isRight) {
^
GuessGame.java:48: cannot find symbol
symbol : variable p2isRight
location: class GuessGame
if (p1isRight || p2isRight || p3isRight) {
^
GuessGame.java:48: cannot find symbol
symbol : variable p3isRight
location: class GuessGame
if (p1isRight || p2isRight || p3isRight) {
^
GuessGame.java:51: cannot find symbol
symbol : variable p1isRight
location: class GuessGame
System.out.println("Player one got it right? " + p1isRight);
^
GuessGame.java:52: cannot find symbol
symbol : variable p2isRight
location: class GuessGame
System.out.println("Player two got it right? " + p2isRight);
^
GuessGame.java:53: cannot find symbol
symbol : variable p3isRight
location: class GuessGame
System.out.println("Player three got it right? " + p3isRight);
^
9 errors


I'm not really sarcastic or condescending, It's a speech impediment.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39885
    
  28
Those errors look like spelling mistakes. The tiniest spelling difference, eg P1isRight and p1isRight will produce that sort of error message.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39885
    
  28
And welcome to JavaRanch
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39885
    
  28
Yes the ^ appeared in the correct place. I presume you have got those variables in the correct scope? If you declare them in the wrong place, depending how many { and } they have before them, they may go "out of scope" and vanish when the compiler comes to them. You will find scoping easier to understand if you use the indentation conventions here (ยง1.1) you will probably find the brace structure easier to read than if you have { at the end of a line. Then you can see how far the declaration of those variables is to the right.
Luke McAllister
Greenhorn

Joined: Sep 07, 2009
Posts: 5
That was my first thought, I did find a plisRight in this class (lower case "L" instead of a number 1) the first time compiling. But I corrected it and recompiled and got the same error. I even changed all the variables to d1isRight etc. (because I have no idea what I am doing) same 9 errors pointed to the same spot. Is it possible the errors are in reference to the two other class files in this program? (I don't think so because the variable isn't in the other files) or is it in some reference to other objects in this class? eg "Player p1" "p1 = new Player()"
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39885
    
  28
What page is it on?
Luke McAllister
Greenhorn

Joined: Sep 07, 2009
Posts: 5
Here is the code I typed from GuessGame.java

and on my screen on this forum the "^" are not where they are supposed to be after the first 3 errors in the terminal, they are at the beginning of the line and in the terminal they are all under the lower case "p"

Luke McAllister
Greenhorn

Joined: Sep 07, 2009
Posts: 5
Campbell Ritchie wrote:What page is it on?


in the book Head First Java 2nd edition its page 38, 39, 40
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39885
    
  28
Your quoted code has spelling differences in. You declared p1isright with small letters throughout and used it as p1isRight with a capital. The style with the capital at the beginning of the "right" is better, but the compiler cannot cope with the spelling difference.
Luke McAllister
Greenhorn

Joined: Sep 07, 2009
Posts: 5
Well that is embarrassing, I totally see it now. I promise I looked for it before but the error codes were pointing to the little "p" so I was looking in the wrong place - it was the "r" ! Fixed and recompiled just fine this time!

Lessons learned;
1.) Might not be a good idea to tackle a new chapter at midnight
2.) Computers don't lie (unless they are running a program which enables/forces them to)
3.) JavaRanch is a good place for help if you are a beginner.


Thanks Campell I think I better get some sleep now.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39885
    
  28
We ahve all done that sort of thing.

And you're welcome
 
 
subject: Head First Java - Having a problem with GuessGame