Question: Java code Guessing Game Refinement. (The user thinks of a number and the program guesses it) Program should be able to guess correctly in 7

Java code Guessing Game Refinement. (The user thinks of a number and the program guesses it) Program should be able to guess correctly in 7 tries or lower.
 Java code Guessing Game Refinement. (The user thinks of a number
Initialize a variable that represents the lowest possible number to 0 (what type should this be?)
Initialize a variable that represent the highest possible number to 100 (what type should this be?)
Initialize a Boolean variable that represents if weve achieved the correct guess to false
Initialize a variable in which to store the number of guesses weve made to 0
Declare a variable in which to store an initial guess
Declare a variable to store user input (make this an int)
Initialize a Scanner object (call the variable you assign it to input for consistency with class examples)
Prompt the user to choose a number (this is simply output the program shouldnt know the number)
Make an initial guess and store it.
Increment the value in the variable storing number of guesses.
Present guess to the user
Present prompt to user (Enter 1 if this was a correct guess, 2 if your number is higher, and 3 if your number is lower:) Use Scanner to grab the nextInt() the user types in, and store it.
If the user has typed in a 1
Change the value of the Boolean variable (correctGuess) to true.
While we havent guessed the correct number (correctGuess == false)
Modify range for next guess
Generate a next guess
Present guess to the user
Present prompt to user (Enter 1 if this was a correct guess, 2 if your number is higher, and 3 if your number is lower:)
Use Scanner to grab the nextInt() the user types in, and store it.
If the user has typed in a 1
Change the value of the Boolean variable (correctGuess) to true.
Print out how many steps it took to guess the number

Initialize a variable that represents the lowest possible number to 0 (what type should this be?) Initialize a variable that represent the highest possible number to 100 (what type should this be?) Initialize a Boolean variable that represents if we've achieved the correct guess to false Initialize a variable in which to store the number of guesses we've made to O Declare a variable in which to store an initial guess Declare a variable to store user input (make this an int) Initialize a Scanner object (call the variable you assign it to "input" for consistency with class examples) Prompt the user to choose a number (this is simply output - the program shouldn't know the number) Make an initial guess and store it. Increment the value in the variable storing number of guesses. Present guess to the user Present prompt to user("Enter 1 if this was a correct guess, 2 if your number is higher, and 3 if your number is lower:") Use Scanner to grab the next to the user types in, and store it If the user has typed in a "1" Change the value of the Boolean variable (correctGuess) to true. While we haven't guessed the correct number correctGuess-false) Modify range for next guess Generate a next guess Present guess to the user Present prompt to user("Enter 1 if this was a correct guess, 2 if your number is higher, and 3 if your number is lower:) Use Scanner to grab the nextInt() the user types in, and store it. If the user has typed in a "1" Change the value of the Boolean variable (correctGuess) to true. Print out how many steps it took to guess the number

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!