// RandomPick.java // A solution to CS 5JA assignment 5, part 1a, Winter 2009 // updated by cmc, 2/24/09 // Note: the javadoc comments are not required import java.util.Random; /** Represents a single random pick - an int between a specified minimum and maximum value. Keeps this pick a secret, but will report if a guess is too high, too low, or good. */ public class RandomPick { private int pick; /** Constructs a random pick object. @param min the minimum value. @param max the maximum value (assume >= min). */ public RandomPick(int min, int max) { Random generator = new Random(); int range = max - min + 1; pick = generator.nextInt(range) + min; } /** Checks if the guess is good. @param guess the guess. @return true if the guess equals this random pick. */ public boolean goodGuess(int guess) { return guess == pick; } /** Checks if the guess is too high. @param guess the guess. @return true if the guess is greater than this random pick. */ public boolean highGuess(int guess) { return guess > pick; } /** Checks if the guess is too low. @param guess the guess. @return true if the guess is less than this random pick. */ public boolean lowGuess(int guess) { return guess < pick; } }