import java.util.Random;
import javax.swing.JOptionPane;

/** A high-low guessing game. */
public class HighLowGUI {
 
  /**The number to guess. */
  private int number;

  
  /** 
   * Create a new high-low game with a number
   * to guess between 0 and upperbound. 
   */ 
  public HighLowGUI(int upperbound) {
    
    // a random number generator
    Random r = new Random();

    // set the number to guess to a random integer
    // between 0 and upperbound
    this.number = r.nextInt(upperbound);
  }
  
  /**
   * Guess the number.
   */
  public void makeGuess() {
    
    String inp = JOptionPane.showInputDialog("Enter a number:");
    int guess = Integer.parseInt(inp);
    
    if (guess == this.number) {
      JOptionPane.showMessageDialog(null, "You got it!");
    } else if (guess < this.number) {
      JOptionPane.showMessageDialog(null, "Too low!");
    } else {
      JOptionPane.showMessageDialog(null, "Too high!");
    }
  } 
}