Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please help with this, and leave comments explainging the code you wrote, thank you Write a Lottery class that simulates a 6-number lottery (e.g. Lotto).

Please help with this, and leave comments explainging the code you wrote, thank you

Write a Lottery class that simulates a 6-number lottery (e.g. "Lotto"). The class should have an array of six integers named lotteryNumbers, and another array of six integers named userLotteryPicks. The class' constructor should use the Random class to generate a unique random number in the range of 1 to 60 for each of the 6 elements in the lotteryNumbers array. Thus, there should be a loop that keeps generating random numbers until all 6 numbers are unique. The Lottery class should have a method, getUsersPicks(), which prompts the user to enter 6 unique numbers between 1 - 60, which will be stored in the array of integers named usersLotteryPicks. Thus, there should be validation to ensure that each number the user selects is different from all the other numbers that he/she entered previously, and to keep looping until the user enters 6 unique numbers. Finally, the Lottery class should have a method, checkLotteryMatch(), which will compare the 2 arrays - lotteryNumbers & usersLotteryPicks - and return the number of digits that match. The digits do not have to match in the exact order, so a nested loop should be created that goes through each digit in the user's lottery picks array and compares it to each digit in the lotteryNumbers array, counting each of the matches. The checkLotteryMatch() method will return an int containing the number of matches.

Write a Driver class called the LotteryGame, which instantiates the Lottery class. Once a Lottery object has been created, the driver will call the Lottery object's getUsersPicks() method, followed by the checkLotteryMatch() method. Use the results of the checkLotteryMatch() method to determine if the user is a winner by using the following criteria:

For a 3-digit match, display a message to the user that he/she will receive a free Lottery ticket as the prize

For a 4-digit match, display a message to the user that he/she will receive a $2000 prize

For a 5-digit match, display a message to the user that he/she will receive a prize of $50,000.

For a 6-digit match, display a message to the user that he/she will receive a grand prize of $1,000,000.

If there are no matches, display the following message to the user: "Sorry, no matches today. Try again!"

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

Step: 3

blur-text-image

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

Database Concepts

Authors: David M Kroenke, David J Auer

6th Edition

0132742926, 978-0132742924

More Books

Students also viewed these Databases questions

Question

(1) An example of negative feedback that you received badly.

Answered: 1 week ago

Question

How well do you gain participation and involvement from the group?

Answered: 1 week ago

Question

Who is the client?

Answered: 1 week ago