In JAVA, create a lottery game application. Generate three random numbers, each
ID: 3711963 • Letter: I
Question
In JAVA, create a lottery game application. Generate three random numbers, each between 0 and 9. Allow the user to guess three numbers. Compare each of the user's guess to the three random numbers and display a message that includes the user's guess, the randomly determined three-digit number, and the amount of money the user has won as follows:
make certain that your application accommodates repeating digits. For example, if a user guesses 1,2, and 3, and the randomly generated digits are 1,1, and 1, do not give the user credit for three correct guesses - just one. Save the file as Lottery.java.
matching numbers award ($) any one matching 10 two matching 100 three matching not in order 1,000 three matching in exact order 1,000,000 no matches 0Explanation / Answer
Below is your code. Please add import statements if missing
public class Lottery {
public static void main(String[] args) {
Scanner user_Input = new Scanner(System.in);
Random ranNum1 = new Random();
final int LIMIT1 = 9;
final int TIMES1 = 3;
int users_First_Guess;
int users_Second_Guess;
int users_Third_Guess;
List<Integer> guesses1 = new ArrayList<>();
final int Gen_First = ranNum1.nextInt(LIMIT1);
final int Gen_Second = ranNum1.nextInt(LIMIT1);
final int Gen_Third = ranNum1.nextInt(LIMIT1);
System.out.println("PLEASE ENTER YOUR FIRST GUESS: ");
users_First_Guess = user_Input.nextInt();
guesses1.add(users_First_Guess);
System.out.println("PLEASE ENTER YOUR SECOND GUESS: ");
users_Second_Guess = user_Input.nextInt();
guesses1.add(users_Second_Guess);
System.out.println("PLEASE ENTER YOUR THIRD AND FINAL GUESS: ");
users_Third_Guess = user_Input.nextInt();
guesses1.add(users_Third_Guess);
final double WinTen1 = 10;
final double Win_Hun = 100;
final double Win_Thund = 1000;
final double Win_Million = 1000000;
final int Win_Zero = 0;
System.out.println(Gen_First + " " + Gen_Second + " " + Gen_Third);
List<Integer> lott = new ArrayList<>();
lott.add(Gen_First);
lott.add(Gen_Second);
lott.add(Gen_Third);
if (guesses1.equals(lott)) {
System.out.println("YOU HAVE WON: $" + Win_Million);
} else {
int match_Count1 = 0;
for (Integer guess_Value : guesses1) {
if (lott.contains(guess_Value)) {
match_Count1++;
lott.remove(guess_Value);
}
}
switch (match_Count1) {
case 0:
System.out.println("YOU HAVE WON: $" + Win_Zero);
break;
case 1:
System.out.println("YOU HAVE WON: $" + WinTen1);
break;
case 2:
System.out.println("YOU HAVE WON: $" + Win_Hun);
break;
case 3:
System.out.println("YOU HAVE WON: $" + Win_Thund);
break;
}
}
}
}
Output
PLEASE ENTER YOUR FIRST GUESS:
2
PLEASE ENTER YOUR SECOND GUESS:
3
PLEASE ENTER YOUR THIRD AND FINAL GUESS:
4
3 5 6
YOU HAVE WON: $10.0
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.