I've typed the code for the DotComBust Game in HFJ, and it all compiled, but for some reason, I'm not getting the string prompt to enter a guess or the result of my guess (hit or kill). For those familiar with the game, here's the code. Can someone point out what's wrong? My head is swimming/ spinning from trying to figure it out.
The GameHelper code was ready bake, so if there's a problem somewhere in the getUserInput () method, I'm not seeing it, because I just typed it in an compiled it (it's ahead of what the chapter is teaching). It's supposed to prompt a guess with "enter a guess" and return a result of hit or kill, but after the instructions display, the cursor just blinks and when I enter a guess, nothing happens.
It's probably something small I missed, but I don't see it.
Please don't use so many spaces before your //comments; that makes the code really difficult to read. You will have to use the "preview" button to see the formatting. Which page is this game on? HFJ seems to have several dot-com games in.
Don't know. You are going to have to put some print statements in, so as to follow the flow through your application. Example, new line 20½ in your setUpGame method, which ought to tell you there are 3 members:New line 27½ similar, but see how many members there are in the newLocation list. You will probably find it prints 1 regardless. Are you really supposed to create a new List every time you traverse that loop?
Similarly you can put print statements into the other methods and follow the control flow. A standard debugging technique. The debuggers on IDEs do the same sort of thing, but are quicker.
I don't fully understand the code - some of the code the book hasn't gotten to yet; it simply said (tongue in cheek ) 'back slowly away from this code, except to type it in and compile it.' So at this point I wouldn't know where to begin to deciper/debug it. Like I said, it compiles fine, but after the instructions are displayed, the cursor just sits there, no prompt to enter the guess, and won't display a result when I enter a guess. I'm guessing the problem is somewhere in the getUserInput() method, but I'm not sure exactly where. I typed everything in correctly, so perhaps the problem is the code itself, and it's something I not able to detect because I don't know enough?
P.S. Sorry about the spaces, I was following the format in the book.
Can you tell me which website -- do you mean wickedly smart or the HFJ website (the Head First Series website). There were some downloads there but the were only the DotCom and DotComBust class. I couldn't find the GameHelper class for it on that site.
If you mean wickedly smart website, then there was a link to a download for some JAR files. I downloaded it, but when I tried to open it, it said "The Java JAR file "codeKitechesTiger-1.jar" could not be launched. Check the Console for possible error messages." I'm unfamiliar with JAR files (haven't gotten there yet).
P.S. I found the code online (not the headfirstlabs site) and just copied it into a file. It works now, so I guess I had some kind of typo with my code that I couldn't see. Doh!
I went to the headfirstlabs site and found that link, but it only downloaded the DotCom and DotComBust code.