import java.util.Random;
import javax.swing.JOptionPane;

/**
 * A high low guessing game.
 */
public class HighLow {
  
  /** The number to guess. */
  private int number;
  
  /** 
   * Set the value of the number to guess.
   */
  public HighLow(int x) {
    Random r = new Random();
    
    // number is between 0 and x-1
    number = r.nextInt(x);  
  }
  
  /**
   * Display on message about the guess.
   */
  public void guess() {
    
    String userGuess = 
      JOptionPane.showInputDialog("Guess the number");
    int myGuess = Integer.parseInt(userGuess);
   
    while(myGuess != number) {
      
      if (myGuess > number) {
        JOptionPane.showMessageDialog(null, "Too high");
      } else if (myGuess < number) {
        JOptionPane.showMessageDialog(null, "Too low");
      } 
      
      userGuess = 
        JOptionPane.showInputDialog("Guess the number");
      myGuess = Integer.parseInt(userGuess);  
    }
    
    JOptionPane.showMessageDialog(null, "You got it");
  }
  
  
}
