Question: Revise Listing 3.8, Lottery.java, to generate a lottery of a threedigit number. The program prompts the user to enter a three-digit number and determines whether

Revise Listing 3.8, Lottery.java, to generate a lottery of a threedigit number. The program prompts the user to enter a three-digit number and determines whether the user wins according to the following rules:

Listing 3.8

1 import java.util.Scanner; 3 public class Lottery { public static void main(String[)

args) { // Generate a lottery number int lottery = (int)(Math.random() *

1. If the user input matches the lottery number in the exact order, the award is $10,000.

2. If all digits in the user input match all digits in the lottery number, the award is $3,000.

3. If one digit in the user input matches a digit in the lottery number, the award is $1,000.

1 import java.util.Scanner; 3 public class Lottery { public static void main(String[) args) { // Generate a lottery number int lottery = (int)(Math.random() * 100); // Prompt the user to enter a guess Scanner input = new Scanner(System.in); System.out.print("Enter your lottery pick (two digits): "); int guess = input.nextInt(); 8. 11 12 // Get digits from lottery int lotteryDigitl = lottery / 10; int lotteryDigit2 = lottery % 10; 13 14 15 16 17 18 19 // Get digits from guess int guessdigitl - guess / 10; int guessDigit2 - guess % 10; 20 21 22 System.out.print1n("The lottery number is " + lottery); // Check the guess if (guess == lottery) System.out.print1n("Exact match: you win $10,000"); else if (guessDigit2 == lotteryDigitl && guessDigitl == lotteryDigit2) System.out.println("Match all digits: you win $3,000"); else if (guessDigitl !! guessDigitl ii guessDigit2 == lotteryDigit1 ii guessDigit2 System.out.printIn("Match one digit: you win $1,000"); 23 24 25 26 27 28 29 lotteryDigitl lotteryDigit2 30 =3D 31 lotteryDigit2) 32 33 34 else 35 System.out.println("Sorry, no match"); 36 37 } wwww HNm 567 0090 Enter your lottery pick (two digits): 15 Jerter The lottery number is 15 Exact match: you win $10,000 Enter your lottery pick (two digits): 45 Peter The lottery number is 54 Match all digits: you win $3,000 Enter your lottery pick: 23 Joter The lottery number is 34 Match one digit: you win $1,000 Enter your lottery pick: 23 er The lottery number is 14 Sorry: no match line# variable 11 14 15 18 19 33 lottery 34 guess 23 lotteryDigitl lotteryDigit2 guessDigitl 2. guessDigit2 Output Match one digit: you win $1,000

Step by Step Solution

3.46 Rating (162 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

Output Enter your lottery pick 630 Match one digit you win 1000 To generate a lottery of 3 digit num... View full answer

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 Java Programming Questions!