Question: Your program will choose a random 4 digit number as the secret number. Your program must prompt the user to enter a 3 digit number
Your program will choose a random 4 digit number as the secret number. Your program must prompt the user to enter a 3 digit number as their guess. The program will respond with a message indicating how many of the digits in the users guess are the same as the digit in the same position in the secret number.For example, if the secret number is 374, and the users guess is 473, then the program would respond with the message You matched 1, because only one of the digits (the 7) in the users guess is the same as the digits in the same position in the secret number. The program will allow the user to continue to enter guesses until they guess the correct secret number.After the user has entered the secret number, the program will output a count of the total number of guesses the user took to find the secret number. Then the program will ask the user if they would like to play again. If the user answers yes, then the program will choose another random 3 digit number and play continues as described above.
Key points: Write programs that use loops to repeat instructions, Demonstrate the use of while or for loops in Java, Use conditional expression to control loops and decisions
SAMPLE OUTPUT:
Guess the 3 digit number!
Guess 1: 000
You matched 0
Guess 2: 1111
You matched 1
Guess 3: 123
You matched 1
Guess 4: 244
You matched 2
Guess 5: 144
You matched 3
Congratulations! You guessed the right number in 5 guessed. Would you like to play again (yes/no)?
** Using this template
While the user wants to play another game Pick a new secret number While the user's guess is not completely correct Prompt the user to make a guess User enters a guess Display number of correct digits in users guess Congratulate the user and tell them the number of guesses they took Ask the user if they want to play again
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
