Question: What to submit: By the deadline, submit 1. two .java files containing the two classes respectively, on Moodle. (Note: Make sure you submit the .java

What to submit:

By the deadline, submit

1. two .java files containing the two classes respectively, on Moodle. (Note: Make sure you submit

the .java files, not the .class files. Submit the .class files only will result in a mark of 0/100.)

2. A hard copy printout of the .java files to my drop box on the third floor of DB. (Note: Make sure

you add a cover page that includes your course number, section, name, and student number.)

Description:

Design and implement an application that simulates a simple slot machine.

Requirements:

1. Write a slot machine that has the following functionalities (assuming all coins are the same):

a. Entering coins: adding coins to the slot machine;

b. Pulling the lever: generating three random numbers;

c. Paying out: depending the outcome of pulling the lever (the three numbers), pay the

player coins according to the following rules: (1) If all three numbers are equal to 1, the

player has hit a jackpot pay the player the number of coins he/she has entered

multiplied by a random integer ranging from 1 to 10; (2) If all three numbers are equal,

but not 1, then pay the player the number of coins entered multiplied by 4; (3) If only

two out of the three are equal, then pay the player the number of coins entered

multiplied by 2; (4) if none of the numbers are equal, then pay nothing.

2. Write a driver program that uses the slot machine class above to simulate a game by:

a. Asking the player for the number of coins he/she has in hand; validating the player input

(must be positive);

b. Creating a slot machine;

c. Repeatedly doing the following:

i. Asking the player how many coins he/she would like to bet;

ii. Validating the player input must be a number between 1 and the number of

coins the player has in hand at that moment;

iii. Entering the coin into the slot machine;

iv. Pulling the lever of the slot machine;

v. Calculating the payout amount and paying it to the player, increasing the

number of coins he/she has in hand; printing out the payout he/she gets this

time and the total number of the coins he/she now has in hand;

vi. Declaring the game is over when the player has no more coins left in hand;

vii. Asking whether the player would like to continue playing if he/she still has some

coins in hand; terminating the game when the player enters n or N;

continuing otherwise.

Marking:

Your submission will be marked on correctness, style (indentation, variable naming, etc.), and

comments. Code that does not compile can receive at most 20/100.

Sample Run 1:

How many coins do you have?

5

How many coins would you like to bet?

1

You get 2 coins. You now have 6 coins.

Continue? Enter 'n' to end the game, or anything else to continue.

y

How many coins would you like to bet?

2

You get 4 coins. You now have 8 coins.

Continue? Enter 'n' to end the game, or anything else to continue.

y

How many coins would you like to bet?

5

You get 0 coins. You now have 3 coins.

Continue? Enter 'n' to end the game, or anything else to continue.

y

How many coins would you like to bet?

2

You get 0 coins. You now have 1 coins.

Continue? Enter 'n' to end the game, or anything else to continue.

y

How many coins would you like to bet?

2

Invalid input. Please enter a number between 1 and 1

How many coins would you like to bet?

1

You get 0 coins. You now have 0 coins.

No more coins. Game over.

Sample Run 2:

How many coins do you have?

4

How many coins would you like to bet?

2

You get 0 coins. You now have 2 coins.

Continue? Enter 'n' to end the game, or anything else to continue.

n

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!