/** GuessingGame.java uses a do loop to play the "guess my number" game.
 * @author Joel Adams, for Alice+Java.
 */
import java.util.Scanner;
import java.util.Random;

public class GuessingGame {
	public void play() {
		Random rng = new Random();
		Scanner kbd = new Scanner(System.in);
		int guessCount = 0;
		int number = rng.nextInt(100) + 1;
		boolean done = false;
		do {
			guessCount++;
			System.out.print("Enter your guess: ");
			int guess = kbd.nextInt();
			if (number < guess) {
				System.out.print("Lower...  ");
			} else if (number > guess) {
				System.out.print("Higher... ");
			} else {
				System.out.println("\nYou guessed my number in "
						+ guessCount + " guesses!");
				done = true;
			}
		} while (!done);
	}
}
