This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Head First Java DotCom, DotComBust, GameHelper Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Head First Java DotCom, DotComBust, GameHelper " Watch "Head First Java DotCom, DotComBust, GameHelper " New topic
Author

Head First Java DotCom, DotComBust, GameHelper

jake dickens
Ranch Hand

Joined: Mar 23, 2011
Posts: 30
I only have one error and I can't find a solution for it here is the code.



one file



second file



third file

the error i get is this

DotComBust.java:45: cannot find symbol
symbol : variable dotComToTest
location: class DotComBust
dotComsList.remove(dotComToTest);
^
Please help.


[Edit: put code between [code] and [/code] ubb code blocks]
Luigi Plinge
Ranch Hand

Joined: Jan 06, 2011
Posts: 441

As the error message says, the problem is in line 45 of DotComBust.java. The variable dotComToTest cannot be found because you don't define it anywhere.

For some reason you have a for-loop using an int x just before it, rather than for (DotCom dotComToTest : dotComsList) as in the book. Are you using a version of Java previous to 1.5? If so, you'll have to reference the list element using the index as you did a few lines above. If not, use the proper for-loop syntax as in the book.
jake dickens
Ranch Hand

Joined: Mar 23, 2011
Posts: 30
i read the book again and it said for(DotCom dotComToTest : dotComsList) and all to it but it still says dotComsList.remove(dotComToTest) is still wrong


also i'm using java the newest one 1.6.26.
Luigi Plinge
Ranch Hand

Joined: Jan 06, 2011
Posts: 441

Maybe try saving your file before you re-compile?
jake dickens
Ranch Hand

Joined: Mar 23, 2011
Posts: 30
the book is wrong on it according to the online version of the code and the downloaded one has the GameHelper imported but does not show it in the book.
Luigi Plinge
Ranch Hand

Joined: Jan 06, 2011
Posts: 441

The online code doesn't work so you conclude the book is wrong?
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11404
    
  81

The error message you are getting is very explicit:

jake dickens wrote:DotComBust.java:45: cannot find symbol
symbol : variable dotComToTest
location: class DotComBust
dotComsList.remove(dotComToTest);


I've pulled out the method that this is referring to. The line numbers are now different, but line 45 in the original source code is equivalent to line 11 in the method shown below:



The error message is telling you that the first time it found the symbol dotComToTest was in line 45 in your code (line 11 above). Does that make sense to you now? Can you see anywhere else in that method where dotComToTest is mentioned (or, more importantly) defined?


The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
jake dickens
Ranch Hand

Joined: Mar 23, 2011
Posts: 30
i downloaded the chapter 6 and compared it to mine and what you said was to make sure but i'm saying the book is wrong cause the book told me dotComToSet not ToTest
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11404
    
  81

You are correct, by the way - there is a mistake in the book.

You can find the Errata for Head First Java online, and search for dotComToTest - the problem with the printed copy of the book is mentioned about a third of the way down the page.

As an aside, I recommend you look for errata anytime you look at any technical book.
Luigi Plinge
Ranch Hand

Joined: Jan 06, 2011
Posts: 441

hmm, that's bad if both the book and the online code are wrong!

My copy of the book is correct, at least. Sounds like you're not so lucky.
jake dickens
Ranch Hand

Joined: Mar 23, 2011
Posts: 30
Online is fine the book i have is incorrect

the online is correct

this is correct

I looked at the online code i had two lines wrong i fixed them.
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11404
    
  81

Jake

Please put code between [code] and [/code] ubb code blocks, otherwise it is too hard to read, and you will find many people will simply move on to easier questions. I fixed your first post for you - you can hit the edit button on that post to see what I have done (or read the link in this post).

As I noted above, this error has been identified in the errata - you are advised to look at it.
Sean Hoar
Greenhorn

Joined: Jan 09, 2012
Posts: 1
Hi, jNewb here as well. I have built the java files like the book 2e + Errata has defined. My code compiles fine, but the output shows that the locationCells are not being set properly. I figure it is something to do with the placeDotCom setter or setLocationCells, but I also noticed that I don't see anything about setting the cells to an array with randomNum locs like in previous versions of the DotComGame. I will include the 3 java files as well as the printed output. All and any help is appreciated.

GameHelper.java



DotCom.java



DotComBust.java



Printed Output:

$ java DotComBust
Your goal is to sink three dot coms.
Pets.com, eToys.com, Go2.com
Try to sink them all in the fewest number of guesses
try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0 try 0

coord 1 = a0 coord 2 = a0 coord 3 = a0

try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0

coord 1 = a0 coord 2 = a0 coord 3 = a0

try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0 try 0 used 0

coord 1 = a0 coord 2 = a0 coord 3 = a0

Enter a guess a0
hit
Enter a guess a0
hit
Enter a guess a0
Ouch! You sunk Pets.com : (
hit
Enter a guess a0
hit
Enter a guess a0
hit
Enter a guess a0
Ouch! You sunk eToys.com : (
kill
Enter a guess a0
hit
Enter a guess a0
Ouch! You sunk Go2.com : (
kill
All Dot Coms are dead! Your stock is now worthless.
It only took you 8 guesses.
You got out before your options sank.
Steve Bradshaw
Greenhorn

Joined: Jul 11, 2012
Posts: 5
Hi Sean Hoar,

IN your game helper class you left out brackets in the while loop

while ( !success & attempts++ < 200 ) {
location = (int) (Math.random() * gridSize);
System.out.print(" try " + location);
int x = 0;
success = true;

this threw the calculations off, as computers read it from right to left
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 37943
    
  22
Welcome to the Ranch , Sean Hoar

Please don’t use such long lines inside the code tags; I have had to put new lines in to make them legible.

Steve Bradshaw, what do you mean about right to left? That sounds incorrect. What you actually mean is that the cast has a higher precedence that multiplication, so (int)a * b has to be changed to (int)(a * b). That is a common mistake; if you cast the random number to an int like the first attempt, you always get 0.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 37943
    
  22
But well done finding that line
 
Don't get me started about those stupid light bulbs.
 
subject: Head First Java DotCom, DotComBust, GameHelper
 
Similar Threads
Head First Java Programs
Head First Java P148 - DotComBust - compile errors
game compile problems
HeadFirstJava - DotCom application
DotComBustGame in HFJ -- not working; can't figure out what I've missed