Question: Write a java program names GuessingGame.java that generates a random integer number between 1 and 10. Then it prompts user to enter a guess (What
Write a java program names GuessingGame.java that generates a random integer number between 1 and 10. Then it prompts user to enter a guess (What is your guess?). First it verifies if the guess is between 1 and 10, If it isnt then prints a message Well, if youre not going to try, Im not playing. Otherwise, it checks whether user has guessed the number correctly. If so, it prints Hurray. You win!. Otherwise, it displays the random number, and then it determines if the number was close. Close means within three numbers before and after random number. It then prints the message You missed it by the miles Or It was close depends on the result. Finally, the program wishes the user good luck by Better luck next time.
Here is the sample run:
What is your guess? 2
The number was 10.
You missed it by the miles.
Better luck next time .
note: you are not supposed to handle non integer guesses.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
