Revise Listing 3.8, Lottery.java, to generate a lottery of a threedigit number. The program prompts the user
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 the user wins according to the following rules:
Listing 3.8
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.
Transcribed Image Text:
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
Fantastic news! We've Found the answer you've been seeking!
Step by Step Answer:
Answer rating: 66% (3 reviews)
Output Enter your lottery pick 630 Match one digit you win 1000 To generate a lottery of 3 digit num...View the full answer
Answered By
Madhur Jain
I have 6 years of rich teaching experience in subjects like Mathematics, Accounting, and Entrance Exams preparation. With my experience, I am able to quickly adapt to the student's level of understanding and make the best use of his time.
I focus on teaching concepts along with the applications and what separates me is the connection I create with my students. I am well qualified for working on complex problems and reaching out to the solutions in minimal time. I was also awarded 'The Best Tutor Award' for 2 consecutive years in my previous job.
Hoping to get to work on some really interesting problems here.
5.00+
1+ Reviews
10+ Question Solved
Related Book For
Introduction to Java Programming, Comprehensive Version
ISBN: 978-0133761313
10th Edition
Authors: Y. Daniel Liang
Question Posted:
Students also viewed these Computer science questions
-
Revise Listing 3.8, Lottery.java, to generate a lottery of a twodigit number. The two digits in the number are distinct.? Listing 3.8 1 import java.util.Scanner; 2 3 public class Lottery { public...
-
Revise Listing 3.4, ComputeAndInterpretBMI.java, to let the user enter weight, feet, and inches. For example, if a person is 5 feet and 10 inches, you will enter 5 for feet and 10 for inches. Here is...
-
Revise Listing 30.10, ParallelMergeSort.java, to define a generic parallelMergeSort method as follows: Listing public static void parallelMergeSort(E[] list) 1 import...
-
2. Two point charges are located at two comers of a triangle as shown. What is the electric potential at the right corner of the triangle? A. 21 10 V C. 4.5 x 10 V B. 3.4 x 10 V D. 6.3 x 10 V 10 em...
-
Solve for 0 2 41. Sin 2 + sin 3 = 0 43. cos 4 + cos 2 = 0
-
Using the references from Exercise 5.3, show the final cache contents for a three-way set associative cache with two-word blocks and a total size of 24 words. Use LRU replacement. For each reference...
-
Consider the IRR and ERR measures of worth. If we define a root to mean a value for the measure that results in \(\mathrm{PW}=0\), then which of the following statements is true? a. Both IRR and ERR...
-
Italian Construction Company purchased a new crane for $360,500 at the beginning of year 1. The crane has an estimated residual value of $35,000 and an estimated useful life of six years. The crane...
-
1. We define the product of operators by composition. That is, AB|4) = A(B|4)). Show that, for the two-level atom, the evolution operator satisfies U(t) U(ts)U(s).
-
The Daytona 500 is a 500-mile automobile race held annually at the Daytona International Speedway in Daytona Beach, Florida. The following crosstabulation shows the automobile make by average speed...
-
Write a program that lets the user guess whether the flip of a coin results in heads or tails. The program randomly generates an integer 0 or 1, which represents head or tail. The program prompts the...
-
Write a program that displays a random coordinate in a rectangle. The rectangle is centered at (0, 0) with width 100 and height 200.
-
As you study accounting, you will become increasingly familiar with a variety of generally accepted accounting principles. Already, you are beginning to appreciate some of the fundamental principles,...
-
consume two goods, What is Min Income required to generate TU=2000 given Tu=10xy Py= 20 . Px= 10
-
Trade benefits A. the factor that is specific to the export sector of each country. B. all factors in the economy. C. the factor that is specific to the import ?competing sectors. D. mobile factors
-
Cranston Industries made an investment of $11,330. In return, the company will receive $23,255 at the end of year 9. How much interest will the company earn on this investment? Assume the interest is...
-
Find y' if cos(x + y) = y sin sin X.
-
Lionel Willemse (age 46), a SA tax resident, made the following gains and losses in the 2024 year of assessment: Loss from sale of rental property - R140 000 Gain from sale of shares - R490 000...
-
Mirzaei Ltd. reported the following information in its balance sheet and income statement for the year ended March 31, 2014: Calculate the net cash provided (used) by operating activities using the...
-
You are planning to purchase your first home five years from today. The required down payment will be $50,000. You currently have $20,000. but you plan to contribute $500 each quarter to a special...
-
Use the Complex class introduced in Programming Exercise 13.17 to develop the ComplexMatrix class for performing matrix operations involving complex numbers. The ComplexMatrix class should extend the...
-
Write a program that meets the following requirements. Randomly create 100 points using Point2D and apply the Arrays. sort(list, Comparator) method to sort the points in increasing order of their...
-
A Java program contains various pairs of grouping symbols, such as: Parentheses: ( and ) Braces: { and } Brackets: [ and ] Note the grouping symbols cannot overlap. For example, (a{b)} is illegal....
-
Activity Purchasing material Receiving material Setting up equipment Machine depreciation and maintenance Ensuring regulatory compliance Shipping Total estimated cost Recommended Cost Driver Number...
-
Jackie Co., a 90% owned subsidiary of Nick Inc., sold land to Nick on May 1, 2024, for $80,000. The land originally cost Jackie $85,000. Jackie reported net income of $200,000, $180,000, and $220,000...
-
The most recent financial statements for AppleBanana Co. are shown here: Income Statement Sales Costs Balance Sheet $ 200,000 130,000 Current assets Fixed assets $ 120,000 280,000 Debt Equity $...
Study smarter with the SolutionInn App