Question
GuessingGame.java 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
GuessingGame.java 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
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started