Class GuessingGame

java.lang.Object
  extended by GuessingGame

public class GuessingGame
extends java.lang.Object

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.

Version:
9/14/15
Author:
Dave Reed

Constructor Summary
GuessingGame(int maxNumber)
          Constructs a GuessingGame object by selecting a number in the specified range.
 
Method Summary
 int getMaximum()
          Accessor method to report the maximum possible number to be guessed (minimum is 1).
 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()
          Resets the game with a new number and reinitialized statistics.
 
Methods inherited from class
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GuessingGame

public GuessingGame(int maxNumber)
Constructs a GuessingGame object by selecting a number in the specified range.

Parameters:
maxNumber - the limit of the range the number can be from (1..maxNumber)
Method Detail

getMaximum

public int getMaximum()
Accessor method to report the maximum possible number to be guessed (minimum is 1).

Returns:
the limit of the range the number can be from

getNumberOfGuesses

public int getNumberOfGuesses()
Accessor method to report the number of guesses made so far.

Returns:
the number of guesses

makeGuess

public java.lang.String makeGuess(int guess)
Takes a user's guess and determines if it is correct, too low, or too high.

Parameters:
guess - the user's guess
Returns:
a message specifying whether the guess is correct, too high, or too low

playAgain

public void playAgain()
Resets the game with a new number and reinitialized statistics.