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

Slot Machine Simulation A slot machine is a gambling device into which the user

ID: 3852320 • Letter: S

Question

Slot Machine Simulation
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 that the slot machine
dispenses back to the user.
Create a JavaFX application that simulates a slot machine. Figure shows an example
of how the GUI should look. The application should let the user enter into a TextField the
amount of money he or she is inserting into the machine. When the user clicks the Spin
button, the application should display three randomly selected symbols. (Slot machines
traditionally display fruit symbols. You will find a set of fruit symbol images in the Student
Sample Programs.) The program should also display the amount that the user won for the
spin, and the total amount won for all spins.

Explanation / Answer

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. "); while (keepPlaying) /*SlotMachineHWCH6.java while (keepPlaying)*/ { System.out.println("Enter your bet"); playerBet = keyboard.nextDouble(); for (i = 1; i
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote