aspose file tools*
The moose likes Beginning Java and the fly likes HeadFirst DotComBust... Help? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "HeadFirst DotComBust... Help?" Watch "HeadFirst DotComBust... Help?" New topic
Author

HeadFirst DotComBust... Help?

Brian Hazzard
Greenhorn

Joined: Apr 26, 2007
Posts: 8
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:



Tech-nerd
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

Maybe you're missing some brackets. Can you post the whole class ?
[ April 26, 2007: Message edited by: Satou kurinosuke ]

[My Blog]
All roads lead to JavaRanch
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

Welcome to JavaRanch!

These all look like the result of a simple typo, like a missing brace or something. Can you post your code?


"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
Brian Hazzard
Greenhorn

Joined: Apr 26, 2007
Posts: 8
Thanks for your replies. Of course I will post my code, which is also available in Head First Java:



If you see something I've neglected, or need to see my other classes, just let me know.
Keith Lynn
Ranch Hand

Joined: Feb 07, 2005
Posts: 2367
Take a look at this.




Check to make sure that the brackets are matched.
Brian Hazzard
Greenhorn

Joined: Apr 26, 2007
Posts: 8
Well, thanks again for your help. It turns out that you were right. There was a missing bracket after the else in the if/else statement. I found it only moments after I posted the code... silly me.

Thanks so much for your help guys (girls?)!
Brian Hazzard
Greenhorn

Joined: Apr 26, 2007
Posts: 8
Thanks keith, for keeping it vague so its a challenge. I appreciate that because I am here to learn!!
Brian Hazzard
Greenhorn

Joined: Apr 26, 2007
Posts: 8
While we are on the topic though... I had a similar problem also when I was developing it in my simplified version. I got this error code:



and here is the SimpleDotComGame class:

fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11498
    
  16

What is the scope of result?

Also, as a heads-up, how will you break out of your while loop?
[ April 27, 2007: Message edited by: Fred Rosenberger ]

There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Brian Hazzard
Greenhorn

Joined: Apr 26, 2007
Posts: 8
In the dotCom class the .checkyourself method sets the isAlive boolean to false if it is a kill, thats when the while breaks.

As far as scope of result... I honestly don't understand what you mean. I am new to the language, could you please explain what scope is?

Thanks,
Brian
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40052
    
  28
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.
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11498
    
  16

Scope basically refers to where a variable exists. So when i say

int fred;

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 ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: HeadFirst DotComBust... Help?