java.lang.Object GuessingGame
public class GuessingGame
Class for playing a simple guessing game.
A GuessingGame object picks a random number from a range, and the user can then
make repeated attempts to guess the number. Each guess results in a message as
to whether the guess was correct, too high, or too low. When done, the user can
determine how many guesses it took to get the number, and can choose to play again
with a different number.
Constructor Summary | |
---|---|
GuessingGame(int maxNumber)
Constructs a GuessingGame object by selecting a number in the specified range. |
Method Summary | |
---|---|
int |
getNumberOfGuesses()
Accessor method to report the number of guesses made so far. |
java.lang.String |
makeGuess(int guess)
Takes a user's guess and determines if it is correct, too low, or too high. |
void |
playAgain(int maxNumber)
Resets the game with a new number and reinitialized statistics. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public GuessingGame(int maxNumber)
maxNumber
- the limit of the range the number can be from (1..maxNumber)Method Detail |
---|
public int getNumberOfGuesses()
public java.lang.String makeGuess(int guess)
guess
- the user's guess
public void playAgain(int maxNumber)
maxNumber
- the limit of the range the new number can be from (1..maxNumber)