I am currently learning java by way of the book Head First Java. I'm at the point in the book where we are doing the DotComBust example game (its just like battleship). If you are familiar with this book example, or just know what the problem below is, please help me out. I have gotten all the bugs out except for the ones listed below:
Which text editor are you using? Get one which supports context highlighting and bracket matching. It makes that sort of error much easier to find. If you are on Windows, try JCreatorLE which is a cut-down IDE, but you can use it as if it were a text editor. On Linux there are excellent products like Kate or Gedit built in.
Scope basically refers to where a variable exists. So when i say
that variable fred doesn't exist until the program dies, it exists until it "goes out of scope".
Generally speaking, a variable goes out of scope when you hit the closing curly bracket that matches the opening bracket before the declaration.
so, you have this block of code:
Since the String result is declared inside this block (the bracket on the while line through the bracket just after NumOfGuesses++), it goes away after that last line. So when you get to your if (result...) line, result does not exist anymore. That's why the compiler is saying "I don't know what result is!!!".
try changing it to this:
Note: you will probably have to make other changes as well, but i didn't want to give it all away. [ April 27, 2007: Message edited by: Fred Rosenberger ]