Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

// each time you restart the game the password must change. Chapter 4, PP 3 Java

ID: 3844281 • Letter: #

Question

// each time you restart the game the password must change.

Chapter 4, PP 3
Java Project Name: IC11_GuessingGame

Develop a Java console application for a simple game of guessing at a secret five-digit code (a random number from 10000 to 99999). When the user enters a guess at the code, the program outputs two values: the number of digits in the guess that are in the correct position and the sum of those digits. For example, if the secret code is 53840 and the user guesses 83241, the digits 3 and 4 are in the correct positions. Thus, the program should respond with 2 (number of correct digits) and 7 (sum of the correct digits). Allow the user to guess until s/he gets it correct.

Here is a sample transaction:

I have randomly chosen a 5-digit code for you to guess.
Each time you guess, I will tell you how many digits are correct and the sum of the digits that are correct.
For example, if the number is "68420" and you guess 12468, I will respond:
Number of Digits Correct: 1
Sum of Digits Correct : 4
From deduction, you will know the 4 was correct in the guess.

Now its your turn..................................................................

Please enter a 5-digit code (your guess):12489
Number of Digits Correct: 1
Sum of Digits Correct : 1

Please enter a 5-digit code (your guess):11358
Number of Digits Correct: 1
Sum of Digits Correct : 1

Please enter a 5-digit code (your guess):14292
Number of Digits Correct: 2
Sum of Digits Correct : 5

Please enter a 5-digit code (your guess):1450
Guess must be a 5-digit code between 10000 and 99999.

Please enter a 5-digit code (your guess):14924
Number of Digits Correct: 5
Sum of Digits Correct : 20
****HOORAY! You solved it. You are so smart****

Explanation / Answer

import java.util.Scanner. utility. Scanner;

public class GuessingGame {

public static void main (String args []){

int secreatnumber;

SecreatNumber =(int)(Math.random()* 999+1);

Scanner keyboard=new Scanner (System.in);

int guess:

do {

System.out.println ("Enter guess number");

guess=keyboard.nextInt ();

if (guess==secreatnumber)

System.out.println("Your guess number is correct", +guess);

else if (guess <secreatnumber)

System.out.println("enter number didn't matched please try again");

else if (guess>secreatnumber)

System.out.println("Enter number is greater then secreatnumber");

}

while (guess!=secreatnumber)

}

}