Write a program that plays a guessing game with the user. The program should gen
ID: 3621554 • Letter: W
Question
Write a program that plays a guessing game with the user. The program should generate a random number between 1 and 100, and then prompt the user repeatedly to guess the number. When the user guesses incorrectly, the game should give the user a hint about the number of digits of the player’s guess matches the correct number. Once the user guesses correctly, the program should print a message showing the number of guesses that the user has made.Sample log of the program execution may be as follows:
Try to guess my two-digit number, and I’ll tell you how many digits from your guess appear in my number.
Your guess? 13
Incorrect (hint: 0 digits match)
Your guess? 26
Incorrect (hint: 0 digits match)
Your guess? 78 Incorrect
(hint: 1 digits match)
Your guess? 70
Incorrect (hint: 2 digits match)
Your guess? 7
You got it right in 5 tries.
Here is what I have so far:
import java.util.Scanner;
import java.util.Random;
public class GuessingGame
{
public static void main(String [] args)
{
int guess;
int guesses;
Scanner Keyboard=new Scanner(System.in);
int number=(int)(100 * Math.random ()) + 1 ;
guesses=0;
do
{
System.out.println("Guess a number between 1 and 100:");
guess=Keyboard.nextInt();
guesses++;
}
while(guess!=number);
{
}
}
}
I am able to generate a random number, and ask the user for an input, but i can't figure out how to play the guessing game with the user.
Please help!
Explanation / Answer
hello
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.