Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

CPT 236 Programming Project 5 Project 5: Chapter 9 - Arrays Problem Definition: Write a lottery program that allows players to select 4 numbers which

image text in transcribed

image text in transcribed

CPT 236 Programming Project 5 Project 5: Chapter 9 - Arrays Problem Definition: Write a lottery program that allows players to select 4 numbers which attempt to match a set of random winning numbers generated by the computer. Required parameters for this problem are: 1. Four (4) random numbers should be generated by the computer and four (4) numbers should be selected by the player. 2. The computer generated numbers and the player selected numbers should be unique, no repeated numbers allowed 3. Allow only numbers between 1 and 25 to be generated by the computer as well as selected by the player. 4. Ordering of the numbers selected by the player should not be required. 5. After the player selects their guesses, the number of matches (any player selection equals any computer generated number) should be totaled and a message printed with the following winning payout information (per each play) -match 0, so payout; match 1, S1 payout; match 2, 55 payout; match 3, S20 payout; match 4, 5100 payout. Also, assuming that a play costs $2print how much the player has made or lost for the play. The program should use the Math.random() method to generate the four (4), unique, random lottery numbers then the player should be queried to enter four (4). unique, guesses. Be sure and use Math.random() correctly in order to generate an integer between 1 and 25: the random method generates a decimal number between 0.0 and 1.0. Use an appropriate loop and an array to store the unique random numbers generated by the computer. Also, use an appropriate loop and an array to store the unique numbers selected by the player. Instructions: Write and submit the Java code that correctly represents a solution to the problem presented above. Some suggestions, hints, concerning the program For step 2, because the numbers should be unique, do not generate a random number (or query the player for a selected number) and assign it to an array location. Assign the number to a temporary variable then check all previous numbers generated (or check all previous numbers selected to make sure the number is truly unique. Put this little process inside a loop which will execute until a unique number is generated (or selected). For step 3, make sure the generated random number (or the player selected number) is between 1 and 25. The Math.random() method can be sealed and shifted with a formula. The player selected number will have to be checked with an if statement and this little process placed inside an appropriate loop which will execute until a correct number is selected. For step 4 (and the program in general), the numbers are not required to be ordered. However, you may find it very easy to work with sorted arrays For step 5, systematically go through all the players' selections, checking each one against all the computer generated numbers, incrementing the total when an exact match is found. Since the numbers are unique, you will not have any over or under counts. Once you have a total, use a case statement to print out the appropriate messages

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

More Books

Students also viewed these Databases questions