home *** CD-ROM | disk | FTP | other *** search
- package num;
-
- import java.util.Random;
-
- public class NumberGuessBean {
- int answer;
- boolean success;
- String hint;
- int numGuesses;
-
- public NumberGuessBean() {
- this.reset();
- }
-
- public void setGuess(String guess) {
- ++this.numGuesses;
-
- int g;
- try {
- g = Integer.parseInt(guess);
- } catch (NumberFormatException var4) {
- g = -1;
- }
-
- if (g == this.answer) {
- this.success = true;
- } else if (g == -1) {
- this.hint = "a number next time";
- } else if (g < this.answer) {
- this.hint = "higher";
- } else if (g > this.answer) {
- this.hint = "lower";
- }
-
- }
-
- public boolean getSuccess() {
- return this.success;
- }
-
- public String getHint() {
- return "" + this.hint;
- }
-
- public int getNumGuesses() {
- return this.numGuesses;
- }
-
- public void reset() {
- this.answer = Math.abs((new Random()).nextInt() % 100) + 1;
- this.success = false;
- this.numGuesses = 0;
- }
- }
-