## Description

In this assignment, you are going to simulate a lottery game machine. The goal of the game is for the player to

match as many numbers to the computer’s as possible. To play the game, they have to pay either $1.00 for one

round or $5.00 for 5 rounds. Each round ends after the player’s numbers have been compared to the computer’s

numbers. After the number of rounds they paid for or they manually quit the game, the total amount of money

they earned is displayed, and the game goes back to the start menu. The user has 3 options during a round:

Choose Numbers, Check Winnings, and Quit.

If the player selects Choose Numbers, they are given two ways to get their lottery numbers: choosing their own

or quick pick. If they choose their own, they enter 5 different numbers from 1 to 20. There CANNOT be

duplicate numbers. If the player enters the same number twice, they see an error message, and have to enter a

new number. If they choose quick pick, the computer will generate 5 different random numbers from 1 to 20 for

them. There CANNOT be duplicate numbers. The 5 numbers chosen by the player or the computer MUST be

stored in an array.

If the player chooses Check Winnings, the player’s numbers are compared to 5 randomly generated numbers

that are the winning numbers. The winning numbers and the player’s numbers are displayed. Then, it states the

number of matches between the winning numbers and the player’s, displays how much money they won that

round, and how many rounds are left. For each number that matches, the player earns $10.00. The winnings are

all added to a total that keeps track of how much money has been won altogether.

Player chooses Quit, the current player’s game ends, the total amount of money won is displayed, and then it

goes back to the start menu. This program should only end if you close the .java file. If the player chooses Quit

before they have used all of their rounds, the remaining money they paid to play the game is added to their total

winnings.

Programming Notes:

You MUST use arrays to store the players 5 numbers and the winning numbers.

You MUST do input validation for all of the user input.

o Numbers must be integers (no floating-point numbers or words)

You MUST use exception handling for this.

o Numbers must be in the correct range.

2

Sample Execution 1: No Errors

Instant Lottery

===============

Price Options:

==============

1. $1.00 for one round.

2. $5.00 for five rounds.

Enter choice (1 or 2): 1

Options:

========

1. Choose Numbers

2. Check Winnings

3. Quit

Enter choice (1, 2, or 3): 1

———————————

Number Options:

===============

1. Choose Your Numbers

2. Quick Pick

Enter choice (1 or 2): 1

Choose 5 Different Numbers

1 2 3 4 5 6 7 8 9 10

11 12 13 14 15 16 17 18 19 20

Number 1: 13

Number 2: 8

Number 3: 1

Number 4: 4

Number 5: 20

Your Numbers: 13 8 1 4 20

———————————

Options:

========

1. Choose Numbers

2. Check Winnings

3. Quit

Enter choice (1, 2, or 3): 2

Winning Numbers: 20 4 11 3 7

Player Numbers: 13 8 1 4 20

Matches: 2

Prize: $20.00

Rounds Left: 0

———————————

Total Prize: $20.00

Please take your winnings.

Thanks for playing!

———————————

Instant Lottery

===============

Price Options:

==============

1. $1.00 for one round.

2. $5.00 for five rounds.

Enter choice (1 or 2): 2

Options:

========

1. Choose Numbers

2. Check Winnings

3. Quit

Enter choice (1, 2, or 3): 1

———————————

Number Options:

===============

1. Choose Your Numbers

2. Quick Pick

Enter choice (1 or 2): 2

Your Numbers: 20 14 2 11 18

———————————

3

Options:

========

1. Choose Numbers

2. Check Winnings

3. Quit

Enter choice (1, 2, or 3): 2

Winning Numbers: 20 19 18 14 5

Player Numbers: 20 14 2 11 18

Matches: 3

Prize: $30.00

Rounds Left: 4

———————————

Options:

========

1. Choose Numbers

2. Check Winnings

3. Quit

Enter choice (1, 2, or 3): 1

———————————

Number Options:

===============

1. Choose Your Numbers

2. Quick Pick

Enter choice (1 or 2): 1

Choose 5 Different Numbers

1 2 3 4 5 6 7 8 9 10

11 12 13 14 15 16 17 18 19 20

Number 1: 1

Number 2: 2

Number 3: 3

Number 4: 4

Number 5: 9

Your Numbers: 1 2 3 4 9

———————————

Options:

========

1. Choose Numbers

2. Check Winnings

3. Quit

Enter choice (1, 2, or 3): 2

Winning Numbers: 2 11 9 12 15

Player Numbers: 1 2 3 4 9

Matches: 2

Prize: $20.00

Rounds Left: 3

———————————

Options:

========

1. Choose Numbers

2. Check Winnings

3. Quit

Enter choice (1, 2, or 3): 1

———————————

Number Options:

===============

1. Choose Your Numbers

2. Quick Pick

Enter choice (1 or 2): 2

Your Numbers: 6 11 8 9 17

———————————

Options:

========

1. Choose Numbers

2. Check Winnings

3. Quit

Enter choice (1, 2, or 3): 2

Winning Numbers: 3 16 15 11 10

Player Numbers: 6 11 8 9 17

Matches: 1

4

Prize: $10.00

Rounds Left: 2

———————————

Options:

========

1. Choose Numbers

2. Check Winnings

3. Quit

Enter choice (1, 2, or 3): 1

———————————

Number Options:

===============

1. Choose Your Numbers

2. Quick Pick

Enter choice (1 or 2): 2

Your Numbers: 2 6 8 17 20

———————————

Options:

========

1. Choose Numbers

2. Check Winnings

3. Quit

Enter choice (1, 2, or 3): 2

Winning Numbers: 4 15 2 17 3

Player Numbers: 2 6 8 17 20

Matches: 2

Prize: $20.00

Rounds Left: 1

———————————

Options:

========

1. Choose Numbers

2. Check Winnings

3. Quit

Enter choice (1, 2, or 3): 1

———————————

Number Options:

===============

1. Choose Your Numbers

2. Quick Pick

Enter choice (1 or 2): 2

Your Numbers: 17 6 5 10 19

———————————

Options:

========

1. Choose Numbers

2. Check Winnings

3. Quit

Enter choice (1, 2, or 3): 2

Winning Numbers: 9 14 5 8 7

Player Numbers: 17 6 5 10 19

Matches: 1

Prize: $10.00

Rounds Left: 0

———————————

Total Prize: $90.00

Please take your winnings.

Thanks for playing!

———————————

Instant Lottery

===============

Price Options:

==============

1. $1.00 for one round.

2. $5.00 for five rounds.

Enter choice (1 or 2): 2

5

Options:

========

1. Choose Numbers

2. Check Winnings

3. Quit

Enter choice (1, 2, or 3): 1

———————————

Number Options:

===============

1. Choose Your Numbers

2. Quick Pick

Enter choice (1 or 2): 2

Your Numbers: 3 15 8 10 2

———————————

Options:

========

1. Choose Numbers

2. Check Winnings

3. Quit

Enter choice (1, 2, or 3): 2

Winning Numbers: 12 4 6 14 2

Player Numbers: 3 15 8 10 2

Matches: 1

Prize: $10.00

Rounds Left: 4

———————————

Options:

========

1. Choose Numbers

2. Check Winnings

3. Quit

Enter choice (1, 2, or 3): 3

———————————

Total Prize: $14.00

Please take your winnings.

Thanks for playing!

———————————

Instant Lottery

===============

Price Options:

==============

1. $1.00 for one round.

2. $5.00 for five rounds.

Enter choice (1 or 2):

6

Sample Execution 2: Errors

Instant Lottery

===============

Price Options:

==============

1. $1.00 for one round.

2. $5.00 for five rounds.

Enter choice (1 or 2): asdf

Enter choice (1 or 2): 234y

Enter choice (1 or 2): 34

Enter choice (1 or 2): 1

Options:

========

1. Choose Numbers

2. Check Winnings

3. Quit

Enter choice (1, 2, or 3): asldf

Enter choice (1, 2, or 3): 897342

Enter choice (1, 2, or 3): -24

Enter choice (1, 2, or 3): 1

———————————

Number Options:

===============

1. Choose Your Numbers

2. Quick Pick

Enter choice (1 or 2): 34

Enter choice (1 or 2): sdf

Enter choice (1 or 2): 1

Choose 5 Different Numbers

1 2 3 4 5 6 7 8 9 10

11 12 13 14 15 16 17 18 19 20

Number 1: 3

Number 2: sdf

Number 2: 987

Number 2: 3

Error! No Duplicates!

Number 2: 19

Number 3: 0

Number 3: 8

Number 4: 19

Error! No Duplicates!

Number 4: 7

Number 5: 4

Your Numbers: 3 19 8 7 4

———————————

Options:

========

1. Choose Numbers

2. Check Winnings

3. Quit

Enter choice (1, 2, or 3):

7

Requirements:

Use an updated comment block

Your program should use the following comment block at the very beginning of your program.

// Name: Your Name Date Assigned: Fill in

//

// Course: CSCI 2003 60357 Date Due: Fill in

//

// Instructor: Ms. Greer

//

// File name: Fill in

//

// Program Description: Brief description of what the program does.

Use appropriate comments throughout the program

Make good use of whitespace

Your output should look exactly like the sample output if using the same data.

Deliverables:

Lottery.java file

Upload 1 file to Moodle

8

Grading:

Total Points 15 points

Lottery class 15 points

Correct input validation for all input 1 point

Gets payment from user to determine number of rounds 0.5 point

Gets games options from user (Choose Numbers, etc) 0.5 point

Number of rounds player gets is correct based on payment 0.5 point

Choose Numbers

Get users choice on how to get lottery numbers. 0.5 point

Choose Your Numbers

Displays numbers 1 -20 correctly 0.5 point

Gets 5 numbers from user 0.5 point

Stores 5 numbers in an array 1 point

Doesn’t allow for duplicate numbers 1 point

Displays chosen numbers 0.5 point

Quick Pick

Uses Random class to generate 5 random numbers 1 – 20 0.5 point

Stores 5 numbers in an array 1 point

Doesn’t allow for duplicate numbers 1 point

Displays chosen numbers 0.5 point

Check Winnings

Compares player’s numbers with computer’s numbers 1 point

Displays number of matches correctly 0.5 point

Displays/calculates amount of money won for the round 0.5 point

Displays number of rounds left correctly 0.5 point

If there’re no more rounds, displays total winnings for game. 0.5 point

If there are more rounds, goes back to Options menu 0.5 point

Quit

Takes user back to start menu 0.5 point

If all the rounds haven’t been used, amount of payment not used

is added total winnings

1 point

Displays total winnings. 0.5 point

Not enough comments/whitespace -1 point

Output does not match the sample executions given in the assignment -1 point

Bad variable names, method names, and/or class names -1 point