import java.util.*; public class GuessANumber { /// fields //////////// private int min; private int max; private int target; private int count; private Random randNumGen = new Random(); /// constructor ///// public GuessANumber(int theMin, int theMax) { min = theMin; max = theMax; pickNumber(); } ///////// methods //////////////////////////// public void pickNumber() { target = randNumGen.nextInt(max - min) + min; } public void playGame() { boolean won = false; int guess; // while you haven't won while (!won) { // ask for a guess guess = SimpleInput.getIntNumber("Guess a number from " + min + " to " + max); count = count + 1; // increment number of guesses // if the guess is correct stop and say they won if (guess == target) { won = true; SimpleOutput.showInformation("You won! It took you " + count + " number of guesses"); } else { if (guess > target) SimpleOutput.showInformation("Too high, try again"); else SimpleOutput.showInformation("Too low, try again"); } } } public static void main(String[] args) { GuessANumber game = new GuessANumber(1,1000); game.playGame(); } }