Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Description A slot machine is a gambling device that the user inserts money into

ID: 3554449 • Letter: D

Question


Description
A slot machine is a gambling device that the user inserts money into and then pulls a lever (or presses a
button). The slot machine then displays a set of randomly-selected images. If two or more of the
images match, the user wins an amount of money that the slot machine dispenses back to the user.

Your assignment is to write a slot machine simulation program. Your program should allow the user to
play a slot machine game. After the user plays a game, your program should write the user

Explanation / Answer

~Slot Machine: A slot machine is a gambling device into which the user inserts money and then pulls a lever or presses a button. The slot machine then displays a set of random images. If two or more of the images match, the user wins an amount of money, which the slot machine dispenses back to the user. Design a program that simulates a slot machine. When the program runs, it should do the following: * Ask the user to enter the amount of money she wants to insert into the slot machine. * Instead of displaying images, the program will randomly select a word from the following list: Cherries, Oranges, Plums, Bells, Melons, Bars. The program will select and display a word from this list three times (like the three columns in a real slot machine). * If none of the randomly selected words match, the program will inform the user that she has won $0. * If two of the words match, the program will inform the user that she has won twice the amount wagered in the first step. * If all three of the words match, the program will inform the user that she has won three times the amount entered. * The program will 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. */ import java.util.Scanner; import java.util.Random; public class SlotMachineHWCH6 { public static void Main(String[] args) { //declarations Scanner keyboard = new Scanner(System.in); //for user input //string slotMachine; //don't know if will be used //double initialPlayerBet; //first bet double playerBet = 0; //subsequent bets //double totalPlayerBets; //total amount user spent in the slot machine double totalWinnings = 0; //total amount won double tripleWin = 0; //amount won when all 3 match double doubleWin = 0; //amount won when 2 match String spin, spin1, spin2, spin3; int i; //counter variable String no; String yes; boolean keepPlaying; //response to prompt to continue playing System.out.println("Slot machine payout: 3 items match - win triple your bet. 2 items match = win double your bet. No match, no win. "); 48 while (keepPlaying) /*SlotMachineHWCH6.java:48: error: variable keepPlaying might not have been initialized while (keepPlaying)*/ { System.out.println("Enter your bet"); playerBet = keyboard.nextDouble(); 55 for (i = 1; i