Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Slot Machine Simulation Prompt the user to enter a seed number for the entire simulation (see below). Asks the user to enter the amount of

Slot Machine Simulation

Prompt the user to enter a seed number for the entire simulation (see below).

Asks the user to enter the amount of money he or she wants to enter into the slot machine.

The simulation will randomly select three words from the following list and display it: apples, peaches, bananas, oranges, berries, plums, grapes, cherries, melons, pears

To select a word, the program can generate a random number in the range of 0 through 9. If the number is 0, the selected word is apples; if the number is 1, the selected word is peaches; and so forth. The program should randomly select a fruit word from this list three times and display all of the three words together.

Rewards

Based on the slot simulation result:

If none of the three randomly selected words match, the program will inform the user that he or she lost the entered amount.

If two of the words match, the program will inform the user that he or she has won 15 times the amount entered.

If three of the words match, the program will inform the user that he or she has won 50 times the amount entered.

If all the three words are "apples", the program will inform the user that he or she has hit the jackpot and has won 300 times the amount entered.

The program will then ask whether the user wants to play again. If so, these steps are repeated. If not, the program displays the total amount of money entered into the slot machine and the total amount won.

Program Detailed Specifications:

***We will give you the random generator that you must use

Your program will start by asking the value for the seed (to create the first random number). If you place the seed into a variable randNumber, then the first random number for gamePlay(int) method is obtained by extracting the last digit of the return value from the the call randNumber = getRandom (randNumber ). You should pass the random number received from this call to generate second random number and last digit of the second random number will be used for gamePLay (int). You can get the third random number in same way.

Important: For the method int getRandom(int rnd), you must use this code below. Remember to extract the last digit from the return value to get the random number in our range (0-9):

 public static int getRandom (int rnd){ long multiplier = 16807; long modulus = 2147483647; return (int)((multiplier * rnd) % modulus); } 

Sample Run#1 for the input 2 3 n:

Welcome to the Slot Machine Simulation. Enter the seed (int > 0) for the random generator: Enter the amount you would like to bet: $ berries melons pears Luck is not on your side! Do you want to play again? (Y/N) You won a total of $0. You made a total bet of $3. 

Sample Run#2 for the input 15 22 Y 9 N:

Welcome to the Slot Machine Simulation. Enter the seed (int > 0) for the random generator: Enter the amount you would like to bet: $ plums melons melons Today is your lucky day. You won $330 Do you want to play again? (Y/N) Enter the amount you would like to bet: $ melons peaches pears Luck is not on your side! Do you want to play again? (Y/N) You won a total of $330. You made a total bet of $31. 
 

Sample Run#3 for the input 2 -3 5 k n:

Welcome to the Slot Machine Simulation. Enter the seed (int > 0) for the random generator: Enter the amount you would like to bet: $ Please enter a positive number. You can't bet zero or negative dollars. berries melons pears Luck is not on your side! Do you want to play again? (Y/N) Please enter a valid response (Y/N): You won a total of $0. You made a total bet of $5. 

Required Decomposition:

main()

int getBetAmount(Scanner keyboard) - Called from the main() method and accepts as a parameter, a scanner object. This method should prompt the user to enter an amount -- Enter the amount you would like to bet: . The program should then return the amount input by the user. Data Validation: Ensure that the user enters a positive number. If user inputs a zero or negative number the program should prompt -- Please enter a positive number. You can't bet zero or negative dollars.

char getPlayAgain(Scanner console) - Called from the main() method and accepts as a parameter, a scanner object. This method should ask the user -- Do you want to play again? (Y/N). Data Validation: Ensure that the user enters either 'y' or 'n'. If user inputs any other character, the program should prompt-- Please enter a valid response (Y/N):

String gamePlay(int fruitIndex) - Called from the main() method and accepts as a parameter, an int value generated randomly using getRandom() method. This method should return the fruit name corresponding to index as a String.

boolean jackpot(String s1, String s2 , String s3)) - Called from the main() method and accepts three strings (the three fruit names) as parameter. This method will return true if all the three fruit names are "apples".

boolean ident3(String s1, String s2 , String s3)) - Called from the main() method and accepts three strings (the three fruit names) as parameter. This method will return true if all the if all the three fruit names are identical but they are not "apples".

boolean ident2(String s1, String s2 , String s3)) - Called from the main() method and accepts three strings (the three fruit names) as parameter. This method will return true if two of the three fruit names and only two fruit names are identical.

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 Design Application Development And Administration

Authors: Michael V. Mannino

4th Edition

0615231047, 978-0615231044

More Books

Students also viewed these Databases questions