CS 5JA, Winter 2009
Assignment 5 - A guessing game, and some array practice

Due: Wednesday, March 11, 9:00 pm
Worth: 100 homework points

  1. Write the following two classes to play a number guessing game with the user:
    1. RandomPick.java - to represent a secret, random number pick (a single integer selected randomly), with methods available to check the accuracy of guesses. Include the following features:
      • An int instance variable to store the random pick.
      • A constructor that takes two int arguments: the minimum and maximum values that define the allowable range from which to pick the random number. This constructor should use a java.util.Random object to select the pick (insuring it is greater than or equal to the minimum, and less than or equal to the maximum).
      • Three predicate methods:
        1. public boolean goodGuess(int guess) - returns true if the guess equals the random pick (or false otherwise)
        2. public boolean highGuess(int guess) - returns true if the guess is greater than the pick
        3. public boolean lowGuess(int guess) - returns true if the guess is less than the pick.
      Download, compile and run RandomPickTest.java to verify your class's public interface is correct, and to test your methods. Verify results match these sample RandomPickTest results from our solution.
    2. GuessNumber.java - to let a user play the guessing game.
      • Match these sample GuessNumber runs - including the menu, prompt and result strings, as well as the error-handling techniques and messages.
      • Use the minima and maxima shown in the sample runs: 1-5 if the user chooses the easy option (i.e., the user enters 1 in response to the menu), 1-20 if the user chooses the medium option, and 1-1000 if the user chooses the difficult option.
      • Note the sample runs at the bottom include error situations. If the user enters improper data, the program does not quit. Instead it gives the user additional chances to get it right.
      • The program should let the user continue to guess until the correct answer is given. Then the program lets the user know the answer is correct, and terminates.
      • It should go without saying, but we expect you to use a RandomPick object in your solution.
  2. Complete CharCounter.java as a class that provides various counts based on a char array that is passed to its constructor.
  3. Turn in RandomPick.java, GuessNumber.java and CharCounter.java here before the deadline.

Updated 2/25/09, by C. Michael Costanzo