Question: Create the Number Guessing Game In this exercise, youll create a simple number guessing game that allows you to guess the value of a random
Create the Number Guessing Game In this exercise, youll create a simple number guessing game that allows you to guess the value of a random number. Each time you make a guess, the game tells you whether your guess is too high or too low. This process repeats until you guess the correct number. A sample run of the application should look like this:
Welcome to the Number Guessing Game
Enter the upper limit for the number: 50
OK, I'm thinking of a number between 0 and 50
Enter your guess: 25
Your guess is too high.
Enter your guess: 20
Your guess is too low.
Enter your guess: 23
Correct!
Bye!
Create the game
1. Start NetBeans and open the project named ch03_ex3_GuessingGame in the extra_ex_starts directory.
2. Review the existing code. Note the use of the Random class. This code generates a random integer between 0 and upperLimit. For the purposes of this exercise, you dont need to understand how it works.
3. Write the code that prompts the user for an upper limit for the guess. This code should set the upperLimit variable which is already defined.
4. Write the code that prompts the user for their first guess.
5. Write the while loop that allows the user to guess again if their guess was wrong. This loop should inform the user whether their guess was too high or too low. Then, it should prompt the user for a new guess. The loop should exit when the users guess is equal to the random number the computer generated.
6. After the while loop, write code that tells the user they guessed correctly.
7. Run the application and make sure it works correctly. Enhance the game
8. Before the while loop, add a variable to keep track of the number of guesses the user has made. Remember to initialize this variable to 1 instead of 0 since the user will need at least one guess to get the correct number.
9. Inside the while loop, increment the variable by one each time the user guesses incorrectly.
10. After the while loop, add a message that tells the user how many guesses they took.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
