Question
- In this assignment, you will be responsible for creating a random number guessing game with a twist. Rather than the computer generating and hiding
- In this assignment, you will be responsible for creating a random number guessing game with a twist. Rather than the computer generating and hiding a number from the player (as is typical), the player will instead choose a number which the computer will attempt to guess. Using prompts that inform the computer whether its guesses are high or low (or that it needs to guess higher or lower), your program should intelligently adjust its guessing range to narrow in on a solution. The program should:
I) Ask user to type lower bound (lb) and upper bound (ub) of a random number. If ((ub-lb<20) || (lb<=0)) then ask user to input again.
II) Generate a random number guess within a valid range using lb and ub. You have to use Random class, like Random rand= new Random();
III) Receive user input regarding how the guessed number relates to the player-held number.
"h", "H" is customary for "high"
"l", "L" is customary for "low"
"c", "C" is customary for "correct"
If not one of the above, ask user to input again.
III) Use the player response to generate a guess within a better range than its previous guess.
IV) End the game when informed that it has reached the correct number.
V) Prompt the user to play again or not and respond appropriately to this input.
"y", "Y" is for again.
"n", "N" is for "stop"
If not one of the above, ask user to input again.
2) (3 pts.) - You should use at least two static variables to store the lowest and highest bounds that the computer can guess between.
A sample log of execution is as follows (user inputs in bold and underlined):
Please input lower bound: 10
Please input upper bound: 20
Upper bound lower bound must be >= 20.
Please input lower bound: 10
Please input upper bound: 40
I guess, the answer is 38
Your answer is (high, low, correct): high
I guess, the answer is 25
Your answer is (high, low, correct): high Please re-type.
Your answer is (high, low, correct): high
I guess, the answer is 10
Your answer is (high, low, correct): low
I guess, the answer is 18
Your answer is (high, low, correct): correct
I am a genius computer!!
Play again? Yes
Please input lower bound: 10 []
Play again? N Thanks for playing!
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