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
-
Considering what you have read in this chapter about individual intervention (in executive and managerial coaching format), what else would you suggest adding to elements of individual intervention?...
-
Which segments of 6.2 were worked with?
-
These financial statement items are for Norsted Company at year-end, July 31, 2014. Instructions (a) Prepare an income statement and an owners equity statement for the year. The owner did not make...
-
The amount of depreciation expense reported in any period maybe a function of four factors: 1) The assets cost 2) Useful life 3)residential value and 4) the depreciation method used. Required: 1)...
-
a. Design the network of Fig. 2.182 to maintain VL at 12V for a load variation (IL) from 0 mA to 200 mA. That is, determine RS and VZ. b. Determine PZmax, for the Zener diode of part (a). 16 V
-
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.
-
A local organization conducted a traffic study to determine if traffic collisions were more likely on Friday and Saturday nights than on other nights. The city council was considering a proposal that...
-
What makes a set of objects a vector space? You will no doubt want to refer to notes and the text, but I'd like you to summarize it for starters. If you have identified a vector space, for example...
-
Walla Walla Company is in its planning stage for next year. Walla Walla expects a big Quarter 3 and is creating a production budget to determine if it needs to hire more employees. Walla Walla knows...
-
Task: P9 P9a P9b P9c P9d Describe the principles and applications of electromagnetic induction Describe using a series of bullet point statements, how transformers work and how their operation...
-
Based on the given information, analyse company's financial health and provide future projections. Unit FY16 FY17 FY18 FY19 Sales Rs. Cr 134 245 371 1,159 PAT Rs. Cr (281) (585) (78) (571) Assets Rs....
-
OBJECTIVE QUESTIONS 1. In each of the following only one statement/item is correct. State which. (i) Financial Accounting helps in (a) ascertaining the financial position of the concerned firm, (b)...
-
Draw the shear and bending-moment diagrams for the beam. 50 Ib/ft 200 lb-ft A B 20 ft 10 ft
-
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....
-
Make a balance sheet and Income Statement A. Con las siguientes transacciones postee en las respectivas cuentas de Activo, Pasivo, Capital, Gasto e Ingreso 1. Se recibe las ganancias de las acciones...
-
For the buyer of 72 Jul Call, calculate the profit or loss (per contract) on the expiration date, when the spot price for CD is $0.7350
-
What if Timcos dividends grow at 6% for one year, than at 10% forever after that?
Study smarter with the SolutionInn App