Question: Write a Java program that randomly generates a three-digit lottery number and prompts the user to enter a three-digit number. Each digit in the number
Write a Java program that randomly generates a three-digit lottery number and prompts the user to enter a three-digit number. Each digit in the number is in the range between 0~9. The program should determine which prize the user wins according to the following rule:
The user wins the first prize if the user input matches all three digits in the lottery number in exact order.
You must use and complete the partially implemented program given below:
import java.util.Scanner;
import java.util.Random;
public class Lab5 {
public static void main(String [] args) {
Scanner in = new Scanner(System.in);
Random rand = new Random();
int g1, g2, g3; //3 digits generated
int u1, u2, u3; //3 digits entered by user
int prize;
g1 = rand.nextInt(10); //generate an integer between 0 and 9
g2 = rand.nextInt(10);
g3 = rand.nextInt(10);
System.out.print("Enter the first digit(0-9):");
u1 = in.nextInt();
System.out.print("Enter the second digit(0-9):");
u2 = in.nextInt();
System.out.print("Enter the third digit(0-9):");
u3 = in.nextInt();
//code to get the prize
The user wins the second prize if the user input matches all three digits in the lottery number, but not in exact order.
The user wins the third prize if the user input matches any two digits in the lottery number in exact positions.
The user wins the fourth prize if the user input matches any two digits in the lottery number, but not in exact positions.
The user wins the fifth prize if the user input matches any single digit in the lottery number in its exact position.
The user wins the sixth prize if the user input matches any single digit in the lottery number, but not in its exact position.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
