April 7th, 2007, 02:29 PM
Bagels(fermi,pico,bagels) code plz help
I need help with this assignment:
Programming Assignment #7
"Repetition and Decision-Making"
I. The Game of Bagels
This assignment is to write an interactive Java program to play the game of Bagels. Here are the rules of the game:
The computer will generate a "secret" three digit number at random. The first number will not be 0, and all the digits will be different. The user tries to guess the number. If the user guesses correctly, then the game is over.
If not, the computer gives a hint and the player tries again.
• for each digit that matches the secret number in the proper place, the computer prints "Fermi"
• for each digit that matches, but not in the proper place, the computer prints "Pico"
• if none of the digits match, the computer prints "Bagels"
Examples (supposing that the secret number is 482):
guess = 637, Bagels
guess = 381, Fermi
guess = 382, Fermi Fermi
guess = 832, Fermi Pico
guess = 328, Pico Pico
guess = 428, Fermi Pico Pico
guess = 482, Winner! (the game is over)
When the game is over, the computer tells the user how many tries it took, and invites the user to play again.
To avoid making it too easy for the player, you should print all Fermis first, and then the Picos, for each guess.
II. High-Level Algorithm for the Game
Generate the Secret Number.
Get User's Guess.
Evaluate User's Guess.
If not winningGuess then
Give User a Chance to Quit.
until (winningGuess or userQuits)
Print results – did user win or quit, number of guesses taken, and a comment (preferably sarcastic)
III. The Bagels Class
Your Bagels class may or may not have a constructor, but either way it will have only one other public method, playGame(). This method will call other private, “utility” methods to:
1. generate the secret number
2. evaluate the current guess and print hints
3. print game results (won or lost, number of guesses, etc)
Private methods can be called only by other methods of the class (e.g. playGame()), and not by the client code. Alternatively, you might want to call the “generate secret number” method from the class constructor, but the other methods will be called from playGame().
IV. The Client Code (i.e., the “Test Class”)
Your test class will create a Bagels object and call the method that plays the game. That is all. Repeat as long as the user wants to play another game, no matter whether she won the previous game or quit.
Last edited by Strobe; April 7th, 2007 at 02:43 PM.
Click Here to Expand Forum to Full Width
This is a CodeGuru survey question.