Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java code a Program that can guess a number between 1 and 100 chosen by the user(You choose a number in your headand the program

Java code a Program that can guess a number between 1 and 100 chosen by the user(You choose a number in your headand the program can guess it). Code the following refinements.
Refinement I: image text in transcribed
Refinement II:
image text in transcribed
Refinement III:
image text in transcribed
Initialize whatever variables we will need Prompt the user to choose a number Make an initial guess and store it. resent this guess to the user and ask the user if we are correct, low, or high hild we haven't guessed the correct number Modify range for next guess Generate a next guess Present this guess to the user and ask the user if we are correct, low, or high 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 0 Declare a variable in which to store an initial guess Prompt the user to choose a number (this is simply output - the program shouldn't know the numbe Make an initial guess and store it. Present this guess to the user and ask the user if we are correct, low, or high Gu d store i While we haven't guessed the correct number Molly work Generate a next guess Present this guess to the user and ask the user if we are correct, low, or high ja p arel 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 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 ohject (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 these yened stor 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) Modo de 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:") en totes les do If the user has typed in a "I" Change the value of the Boolean variable (correetGuess) 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

The Database Management Systems

Authors: Patricia Ward, George A Dafoulas

1st Edition

ISBN: 1844804526, 978-1844804528

More Books

Students also viewed these Databases questions