lab_6_-_guess_game.docx

CS101 S. Thompson

University of Bridgeport Lab 6: Guessing Game

Problem:

In this assignment, you need to create a simple interactive game in which the objective is for you to guess a number chosen by the computer. For each guess you make, the computer reports whether your guess is too high or too low. You will have a maximum of 6 tries per game. After 6 tries, the game starts over with a new number. This continues until you are sick of the game at which point you indicate that you want to quit.

The name of your program should be called GuessGame. You will prompt the user for his or her input. The value should be between 1 and 100. Use the java.util.Random for random guesses.

Hints

This assignment requires the use of if statements, constants, input validation, e.g. input.hasNextInt() from the Scanner class.

Sample Output

Welcome to the guessing game.

I will choose a number between 1 and 100 ... and you try to guess it.

With each guess, I will tell you whether you are high or low.

The objective is to find the number using as few guesses as possible. You have only six guesses.

Let's start!

I am thinking of a number between 1 and 100.

Enter guess (or 0 to quit): 45

That's too high.

Enter guess (or 0 to quit): 23

That's too high.

Enter guess (or 0 to quit): 12

That's too low.

Enter guess (or 0 to quit): 15

*** Correct! You got it in 4 guesses!

Let's play again!

Sample Output Continued…

I am thinking of a number between 1 and 100.

Enter guess (or 0 to quit): 7

That's too low.

Enter guess (or 0 to quit): 6

That's too low.

Enter guess (or 0 to quit): 9

That's too low.

Enter guess (or 0 to quit): 13

That's too low.

Enter guess (or 0 to quit): 36

That's too low.

Enter guess (or 0 to quit): 78

That's too high.

!!!! You lose. My guess was 50

Let's play again!

I am thinking of a number between 1 and 100.

Enter guess (or 0 to quit): 0

Thanks for playing!

Spring 2016

Instructor: Subrina Thompson 2/2