import java.util.Random;
import javax.swing.JOptionPane;
public class PlayHiLo
{
	public static void main(String[] args)
	{
		boolean playAgain = true;

		while (playAgain)
		{
			hiLoGame();
			
			String answer = JOptionPane.showInputDialog
								 (null, "Play another game? YES/NO");
									
			playAgain = answer.equalsIgnoreCase("YES");
		}
		
		System.out.println();
		System.out.println("Thanks for playing HI_LO");
	}
	
	private static void hiLoGame()
	{
		System.out.println();
		System.out.println("Welcome to my HI_LO game");
		Random generator = new Random();
		int secret = generator.nextInt(100) + 1;	// 1.. 100
		
		boolean done = false;
		do
		{
			String answer = JOptionPane.showInputDialog
			                (null, "Guess a number between 1 .. 100" + 
								        "\n or click CANCEL to quit");
			if (answer == null)
				done = true;
			else
			{
				int guess = Integer.parseInt(answer);
				done = checkAnswer(guess, secret);
			}
		} while (!done);
	}
	
	private static boolean checkAnswer(int guess, int secret)
	{
		boolean correct;
		
		if (guess == secret)
		{
			correct = true;
			System.out.println(guess + " You Got It !!");
		}
		else
		{
			correct = false;
			if (guess < secret)
				System.out.println(guess + " is too LOW");
			else
				System.out.println(guess + " is too HIGH");
		}
		return correct;
	}
}	