Question: Write a number guessing game program named GuessingGame.java The program will generate a secret random number between 1 and 50 (inclusive). Use java.util.Random. The program

Write a number guessing game program named GuessingGame.java The program will generate a secret random number between 1 and 50 (inclusive). Use java.util.Random.

The program will continue prompting the user to guess the secret number until they guess it correctly. The program ends when the user successfully guesses the secret number.

Every time you prompt the user, use a while loop with the Scanner hasNextInt() method to make the program robust. If the user didn't enter an integer, discard their input, and reprompt with "Not an integer, guess again: ". If the entered value is outside the range (not from 1 - 50), reprompt with Out of range, guess again: ". The program should do the following:

Prompt the user for a guess (an integer value from 1 - 50, inclusive) While the guess does not equal the secret number: If the guess is larger than the generated random number, tell the user it is larger than the secret number and reprompt for another guess. If the guess its smaller than the generated random number, tell the user it is smaller than the secret number and reprompt for another guess.

Once the guess equals the secret number, tell the user that they guessed the secret number and they win! Here is a sample output from running your program:

Welcome to the Guessing Game. Try to guess the secret number between 1 and 50 (inclusive).

Your guess? 60 Out of range, guess again: z Not an integer, guess again: 30 30 is larger than the secret number

Your guess? 5 5 is smaller than the secret number

Your guess? 0 Out of range, guess again: 10 10 is smaller than the secret number

Your guess? 20 20 is larger than the secret number

Your guess? 15 15 is smaller than the secret number

Your guess? 18

You win! You guessed the secret number: 18

do not use break, try/catch.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!