• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Head First Java - Having a problem with GuessGame

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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

 
Marshal
Posts: 79178
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Those errors look like spelling mistakes. The tiniest spelling difference, eg P1isRight and p1isRight will produce that sort of error message.
 
Campbell Ritchie
Marshal
Posts: 79178
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And welcome to JavaRanch
 
Campbell Ritchie
Marshal
Posts: 79178
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Marshal
Posts: 79178
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What page is it on?
 
Luke McAllister
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:What page is it on?



in the book Head First Java 2nd edition its page 38, 39, 40
 
Campbell Ritchie
Marshal
Posts: 79178
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Marshal
Posts: 79178
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
We ahve all done that sort of thing.

And you're welcome
 
The harder I work, the luckier I get. -Sam Goldwyn So tiny. - this ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic