aspose file tools*
The moose likes Java in General and the fly likes Guessing Game Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Guessing Game" Watch "Guessing Game" New topic
Author

Guessing Game

William Koch
Ranch Hand

Joined: Sep 26, 2012
Posts: 76
Can anyone help me come up with the classes and methods needed for this program. I can write them myself. I just need some ideas for the design and some test plans. All of which I can write on my own. I am just asking for some suggestions on how you all at the ranch would tackle this problem as experienced programmers.

I need to write a program that can learn about players in a particular sport. The program will play a game in which the user thinks of a player, and the program tries to guess the player. When it fails to guess the player, the program solicits information from the user that will help it do better next time. For example, here is a sample transcript of the program in action (computer output in black, user input in red italics):

Pick a sport: basketball
I don't know anything about basketball. Please teach me.
Who is your favorite player? Magic Johnson

Ok, think of a player and I will try to guess who it is. Ready? Yes
Is it Magic Johnson? No
I give up. Who is it? Michael Jordan
Please enter a question whose answer is yes for Michael Jordan
and no for Magic Johnson:
Is he known for sticking his tongue out?

Ok, think of a player and I will try to guess who it is. Ready? Yes
Is he known for sticking his tongue out? No
Is it Magic Johnson? No
I give up. Who is it? Mugsy Bogues
Please enter a question whose answer is yes for Mugsy Bogues
and no for Magic Johnson:
Is he shorter than 6 feet?

Ok, think of a player and I will try to guess who it is. Ready? Yes
Is he known for sticking his tongue out? No
Is he shorter than 6 feet? Yes
Is it Mugsy Bogues? Yes
I win!

Ok, think of a player and I will try to guess who it is. Ready? No

Good-bye. Pick basketball next time to continue game.

Between sessions, the program will save the information it knows in a file named game.txt, where game is the name entered by the user. (In this case, the file would be basketball.txt.) If the user picks the same game later, the program will re-load what it already knows about that game. For example, the next session might proceed

Pick a sport: basketball

Ok, think of a player and I will try to guess who it is. Ready? Yes
Is he known for sticking his tongue out? Uh-huh
I'm sorry. I didn't understand that answer. Let's try again.
Is he known for sticking his tongue out? Yes
Is it Michael Jordan? Yes
I win!

Ok, think of a player and I will try to guess who it is. Ready? Yes
Is he known for sticking his tongue out? No
Is he shorter than 6 feet? Yes
Is it Mugsy Bogues? No
I give up. Who is it? Spud Webb
Please enter a question whose answer is yes for Spud Webb
and no for Mugsy Bogues:
Did he win the Slam Dunk contest?

Ok, think of a player and I will try to guess who it is. Ready? No

Good-bye. Pick basketball next time to continue game.

Thanks for your help!
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11317
    
  16

as always, you start by NOT thinking about java, or classes, or data structures, or methods. You start by writing down in english what needs to be done. You then refine it and clarify. Eventually, you get to the point where you start realizing what sorts of classes/methods you need.

I would start by writing down something like

"I need to keep track of players in different sports. So I need a bunch of basketball players, a bunch of baseball players, etc. I won't know what all sports may be included, so I need to be able to add new ones on-the fly. I will need to keep track of questions that identify each player. Can a single question apply to more than one person? Do I need to be able to pick the question that eliminates the most people? When the user exits, I need to save all the new data - could be in a text file, could be in a database."

So now I realize that (for this), there is no difference between a basketball player and a Darts player. I have a person, I associate a sport with them, and I maintain a list of questions for each player. And I continue on like that.

I would probably spend a day or two thinking about it, running through various scenarios in my head, and writing them all down.

Once I got to the point of coding, I would write VERY small pieces at a time. I never write more than 2-3 lines before I re-compile.


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
William Koch
Ranch Hand

Joined: Sep 26, 2012
Posts: 76
Thanks a lot Fred! I appreciate your feedback. I will give it a shot and post back in a few days!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Guessing Game