import java.util.Random;
/** 
 * A guessing game, where the user tries to guess
 * a randomly generated number.
 */
public class HighLow {
  /** the number to guess. */
  private int answer;
  private int numberOfGuesses;
  
  /** 
   * Constructor which assigns the answer to 
   * our guessing game.
   */
  public HighLow(int i) {
    Random r = new Random();
    
    // number is between 0 and i - 1
    answer = r.nextInt(i);
  }
  /** 
   * Guess method, which gets a number from the user and
   * displays a message, indicating whether the user got
   * it right or not.
   */
  public void guess(int guess) {
    numberOfGuesses++;
    /* when executing an if statement you first test if the condition
     * (in parenthesis) is true, if so, then the statements in the body are 
     * executed.  If it is not, then the statements in the body following
     * the keyword else are executed.
     */
    if (guess == answer) { //the body of statements starts with "{" and ends with "}".
      System.out.println("You're a winner in " + numberOfGuesses + " guesses!");
    } else {
      System.out.println("Oops ... you lose - try again - you have guessed " + numberOfGuesses + " times!");
    }
  }
}
