Loading

Java - Lottery Application Write a Lottery class that simulates a lottery. The class should have an array of five integers named lotteryNumbers. Demonstrate the class in a program (driver) that asks the user to enter five numbers

Availability: In stock

Regular Price: $25.00

Special Price: $15.00

Java - Lottery Application Write a Lottery class that simulates a lottery. The class should have an array of five integers named lotteryNumbers. Demonstrate the class in a program (driver) that asks the user to enter five numbers

Double click on above image to view full picture

Zoom Out
Zoom In

More Views

Quick Overview

Lottery Application


Write a Lottery class that simulates a lottery. The class should have an array of five integers named lotteryNumbers. The constructor should use the Random class (from the Java API) to generate a random number in the range of 0 through 9 for each element in the array. (If you are unsure of how to use the Random class, research it!) The class should also have a method that accepts an array of five integers that represent a person’s lottery picks. The method is to compare the corresponding elements in the two arrays and return the number of digits that match.


For example:














7



4



9



1



3




LotteryNumbers array


 














4



2



9



7



3




User’s array


There are two matching digits (elements 2 and 4).


In addition, the class should have a method that returns a copy of the lotteryNumbers array.


 


Demonstrate the class in a program (driver) that asks the user to enter five numbers. The program should display the number of digits that match the randomly generated lottery numbers. If all of the digits match, display a message proclaiming the user a grand prize winner.


Validation: You will need to validate the user’s input prior to adding it to the array. Create a method in the driver to test the user’s input (0-9 only).


 

Regular Price: $25.00

Special Price: $15.00

Details

Lottery Application

Write a Lottery class that simulates a lottery. The class should have an array of five integers named lotteryNumbers. The constructor should use the Random class (from the Java API) to generate a random number in the range of 0 through 9 for each element in the array. (If you are unsure of how to use the Random class, research it!) The class should also have a method that accepts an array of five integers that represent a person’s lottery picks. The method is to compare the corresponding elements in the two arrays and return the number of digits that match.

For example:

7

4

9

1

3

LotteryNumbers array

 

4

2

9

7

3

User’s array

There are two matching digits (elements 2 and 4).

In addition, the class should have a method that returns a copy of the lotteryNumbers array.

 

Demonstrate the class in a program (driver) that asks the user to enter five numbers. The program should display the number of digits that match the randomly generated lottery numbers. If all of the digits match, display a message proclaiming the user a grand prize winner.

Validation: You will need to validate the user’s input prior to adding it to the array. Create a method in the driver to test the user’s input (0-9 only).

 

Additional Information

Programming Language Java

Product Tags

Use spaces to separate tags. Use single quotes (') for phrases.