Question
Create a class called GuessTheNumber that generates a random number between 1 and 10, inclusive. It will then ask the user to guess the number
Create a class called GuessTheNumber that generates a random number between 1 and 10, inclusive. It will then ask the user to guess the number between 1 and 10, inclusive, and display one of the following messages:
Your guess is too high
Your guess is too low
You guessed correctly in nn guesses!
If the user guesses incorrectly, indicate if the guess was too high or too low, and continue asking for a guess until the user guesses the number. The class should count the number of guesses it took the user, and display that value for nn.
The class should have at least the following two methods: a public method named play which actually plays the game; and private method named askForNumber which asks the user for their guess. Make sure to perform error checking on the users input.
Create a second class called GuessTheNumberTest that plays the game. The class should play the game at least once, and then ask the user if they would like to play the game again. Keep playing the game until the user decides they want to stop
For all both classes, comment all method, and at the start of any control statements.
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