This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
I am just starting out learning Java using this text book. I finished reviewing chapter 2 and have run the GuessGame in Eclipse as written in the book. I am trying to make a change so that within the player object I can store the number of times a player guesses a specific number (5 for example). I then want to have this printout at the end of the game to say "player 1 guessed 5 x times), player 2 guessed 5 x times, etc....
I made the following changes to the code and thought I am getting no errors this is not working as intended so I am definitely missing something here. Below is the code in the player and guess game classes with my changes. Any suggestions to point me in the right direction would be appreciated.
You've defined a counter in your Player class as an int variable called "guessFive." That looks fine.
But in your GuessGame class, you define String variables for each player (like "p1guessFive") and set these to null. These have no relation to the int counters in your Player instances, nor do they ever get assigned a value other than null. Do you see why?
"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
Welcome to JavaRanch
I don't have that book (I ought to buy a copy) but I have seen that guessing game many times: here on the beginner's forum. A search for "GuessGame" will probably find several previous discussions, and you can see how others handled their problems.
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com