FileDocCategorySizeDatePackage
NumberGuessBean.javaAPI DocApache Tomcat 6.0.141830Fri Jul 20 04:20:34 BST 2007num

NumberGuessBean

public class NumberGuessBean extends Object

Fields Summary
int
answer
boolean
success
String
hint
int
numGuesses
Constructors Summary
public NumberGuessBean()

    reset();
  
Methods Summary
public java.lang.StringgetHint()

    return "" + hint;
  
public intgetNumGuesses()

    return numGuesses;
  
public booleangetSuccess()

    return success;
  
public voidreset()

    answer = Math.abs(new Random().nextInt() % 100) + 1;
    success = false;
    numGuesses = 0;
  
public voidsetGuess(java.lang.String guess)

    numGuesses++;

    int g;
    try {
      g = Integer.parseInt(guess);
    }
    catch (NumberFormatException e) {
      g = -1;
    }

    if (g == answer) {
      success = true;
    }
    else if (g == -1) {
      hint = "a number next time";
    }
    else if (g < answer) {
      hint = "higher";
    }
    else if (g > answer) {
      hint = "lower";
    }