Question: Create a simple Guessing Game program. In the program, ask the user to guess the secret number (between 1 and 100) generated using a Random

Create a simple Guessing Game program. In the program, ask the user to guess the "secret" number (between 1 and 100) generated using a Random class object. (Note: to make the program gradeable by Mimir, I have already generated the random number using a given "seed" value so it won't be truly random when it is tested by the grader).

When the user guesses, print a message indicating whether the guess was too low, too high, or correct. Also print out the number of guesses the user has made so far. If the user guesses correctly, the game ends. If the user's guess is incorrect, allow them to guess again until they get it (use a loop).

Sample output of a game:

Enter the seed value for the random number generator:

1

Guess the number (1-100): 50 Too low. Guess again. You've guessed 1 times. Guess the number (1-100): 80 Too low. Guess again. You've guessed 2 times. Guess the number (1-100): 90 Too high. Guess again. You've guessed 3 times. Guess the number (1-100): 85 Too low. Guess again. You've guessed 4 times. Guess the number (1-100): 86 You guessed it! It took you 5 guesses.

Starter code:-

/* * A simple guessing game program * Note: the generated "secret" number will depend on the seed value given * If the game is played with the same seed value, the same secret number will be chosen each time. */ import java.util.*; public class GuessingGame { public static void main(String[] args) { Scanner scnr = new Scanner(System.in); System.out.println("Enter the seed value for the random number generator:"); int seed = scnr.nextInt(); Random r = new Random(seed); int secretNum = r.nextInt(100)+1; //TODO: Complete the program } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!