ITEC 120 LAB 7 Back to Lab index page

2 Guesses

You will write Java program that will pick a number between 1 and 7 and give the user 2 chances to guess what it is. If the user misses on the first try, your program will tell them whether they need to guess higher or lower. If they miss on the second try, your program will tell them what the number was. Of course your program will congratulate them if they guess the number.

Sample run

Program outputs:

I'm thinking of a number between 1 and 7.
Guess what it is:

User inputs: 4
Program outputs:

No, guess higher:

User inputs: 6
Program outputs:

Sorry, you missed. The number was: 7

Another sample run

Program outputs:

I'm thinking of a number between 1 and 7.
Guess what it is:

User inputs: 3
Program outputs:

No, guess lower:

User inputs: 2
Program outputs:

Good! That's it!

Yet another sample run

Program outputs:

I'm thinking of a number between 1 and 7.
Guess what it is:

User inputs: 4
Program outputs:

YES! You got it in ONE TRY!! WOOOHOOO!

You'll need a random number generator for this program (some examples are in the end of Ch 2.). You'll also use some if statments (beginning of Ch. 3).

For 1 Extra Credit point: Modify your program to let the user choose how many numbers to pick from, for example, if the user chose 5, then the program would generate a number between 1 and 5. And, let the user have 3 guesses.

Extra credit points will be added to your in-class quiz average (so, that's worth 10% on a quiz - like raising 1 quiz grade up a lettergrade.)

Once you have your program working, show your lab to the Peer Instructor to be checked off.