Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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.
image text in transcribed
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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

MySQL/PHP Database Applications

Authors: Brad Bulger, Jay Greenspan, David Wall

2nd Edition

0764549634, 9780764549632

More Books

Students also viewed these Databases questions