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
-
What are the different ways to optimize an object system?
-
How much money can be withdrawn at the end of the investment period if a. $1,000 is invested at 8 percent/year compounded annually for 10 years? b. $5,000 is invested at 11 percent/year compounded...
-
A governments MD&A states that government-wide net position decreased as a result of the issuance of a long-term liability during the current reporting period. Does this sound correct? How does the...
-
respond to this response, "I chose financial advisor and accountants because they have similar areas they work on and financial provides guidance on financial planning for businesses or people where...
-
Equipment acquired on January 8 at a cost of $212,000 has an estimated useful life of 15 years, has an estimated residual value of $14,000, and is depreciated by the straight-line method. a. What was...
-
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.
-
How can you determine whether a key-value pair exists in a dictionary?
-
Temperance's net worth is $50,000. Her debt ratio is 0.5. Her long-term assets total $90,000, and monthly expenses are $5,000. What is her liquidity ratio?
-
3 steel plates of 6 mm thickness, a total of 4 rivets, each 11 mm in diameter, at the corners of an equilateral triangle with one side 123 mm long (rivet no. 1, 2 and 3) and in the center of this...
-
Teddy's gross income is $100,000 and her disposable income is $70,000. Her savings ratio is 6%. What is the minimum emergency fund should she maintain?
-
Consider the two-dimensional AND dataset D that contains the following 4 examples with binary labels D = {(x1,t1), (x2, t2), (X3, t3), (x4, t4)} = {([0,0], -1), ([1, 1], +1), ([0, 1], 1), ([1,0],...
-
You are the current owner of a house which you bought yesterday for 500K while having 100K of your own equity to put down. You have a 25 year mortgage payable monthly and which costs you $2024 a...
-
Using the legend provided, classify each of the following statements: Legend A = Tax avoidance E = Tax evasion N = Neither a. Sue writes a $707 check for a charitable contribution on December 28,...
-
Refer to Exercise 8.S.I. Construct a scatterplot of the data. Does the appearance of the scatterplot indicate that the pairing was effective? Explain. Exercise 8.S.I. A volunteer working at an animal...
-
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....
-
Consider the case of Alexander Industries: Alexander Industries is considering a project that requires an investment in new equipment of $3,570,000. Under the new tax law, the equipment is eligible...
-
Consider an investment where shares are bought @ Rs . 1 5 0 and sold @ Rs . 4 1 0 . The investment is held for 3 years. Calculate HPR and HPY. If shares bought @ Rs . 2 0 0 and sold @Rs . 1 1 0 and...
-
the quantum well shown below: V(x) = Vo I II III x = 0 x = a Figure 1: Quantum Well for Problem 1 (a) Find the wavefunction general solution for each region (41(x), 11(x), and III(x)). You may assume...
Study smarter with the SolutionInn App