Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

5. Variation of the Lottery Problem: Write a Java program that first generates a random 3-digit positive integer; then prompts the user to enter a

image text in transcribed
5. Variation of the Lottery Problem: Write a Java program that first generates a random 3-digit positive integer; then prompts the user to enter a 3-digit integer him-/herself; then compares the random integer with the user-entered integer and does the following: - If the numbers exactly match: Congratulations! You won the lottery $10,000 prize!"; - If any 2 out of 3 digits match: "Congrats - you won the second prize of $500!; - If exactly one digit matches: You won $10"; - If no digits match: "Sorry, you did not win gets printed on the screen by your code. - If the user entered anything other than a valid 3-digit (positive) integer, your program should warn her/him: "Please try again: enter a positive 3-digit number" (Note: you need to use the Math.random method from Chapter 4 in this problem; for the rest of this assignment, Java features just from Chapters 1 - 3 in Liang suffice.) EXAMPLE: Assume the lottery number is 123 and that Mary picked 100, Bob picked 217 and Ivan picked 723. Then Mary would win $10 (as only one digit matches '123' at the correct position), Bob would not win anything and Ivan would win $500 for two matched digits

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advances In Spatial And Temporal Databases 10th International Symposium Sstd 2007 Boston Ma Usa July 2007 Proceedings Lncs 4605

Authors: Dimitris Papadias ,Donghui Zhang ,George Kollios

2007th Edition

3540735399, 978-3540735397

More Books

Students also viewed these Databases questions