loop Case Study
Problem: Write a program that
plays a reverse guessing game with the user. The user thinks of a
number between 1 and 10, and the computer repeatedly tries to guess it.
Think of a
number between 1 and 10. Then I, the computer, will try to guess it.
Is it 6?
Is it 8?
Is it 9?
I guessed your
number in 3 guesses!
Sentinel Loop: We will need a loop that ends when the user inputs
What is the sentinel value?
the Problem - One Way
Initialization: initialize program's variables
Process computer's "guesses"/play game
Finish up: calculate and display results
Create Scanner object
Call method that plays the game
Call method that displays results
initialize counter to track number of guesses made
Generate the computer's first guess
while the computer hasn't guessed correctly:
display feedback on guess
generate next guess
takes the number of guesses made as an argument, and