Question: how to convert this program into a GUI application. please help. import java.util.Scanner; import java.util.Random; public class SlotMachineHWCH6 { public static void Main(String[] args) {

how to convert this program into a GUI application. please help.

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 <= 3; i++)/*SlotMachineHWCH6.java getSlotItems(spin);*/ ^ { getSlotItems(spin); getSlotItems(spin); System.out.println(spin1 + "," + spin2 + "," + spin3); /* System.out.println(spin1 + "," + spin2 + "," + spin3); + same for spin2 and spin3*/ } spinWinnings(spin1, spin2, spin3);/* spinWinnings(spin1, spin2, spin3); and there are the same messages for spin2, spin3 */ playAgain(yes, no); /* playAgain(yes, no); /*same error for 'yes'*/ ^ } } //get the random 3 slot items out of 6 possible public static String getSlotItems(String spin) { //declarations Random rand = new Random(); //random number generator //map a random number to the items in the list switch(rand.nextInt(6)) { case 0: spin = "Cherries"; System.out.println("Cherries"); break; case 1: spin = "Oranges"; System.out.println("Oranges"); break; case 2: spin = "Plums"; System.out.println("Plums"); break; case 3: spin = "Bells"; System.out.println("Bells"); break; case 4: spin = "Melons"; System.out.println("Melons"); break; case 5: spin = "Bars"; System.out.println("Bars"); break; default: System.out.println("ERROR ERROR ERROR"); break; } return spin; } public static void spinWinnings(String spin1, String spin2, String spin3) { if (spin1 == spin2 && spin2 == spin3) { //double doubleWin; double tripleWin; /*variable playerBet might not have been initialized tripleWin = playerBet * TRIPLE; /*variable playerBet might not have been initialized tripleWin = playerBet * TRIPLE;*/ ^ ^ double playerBet; double newTotal; final int TRIPLE = 3; // to calculate winnings for 3 matches tripleWin = playerBet * TRIPLE; newTotal = playerBet + tripleWin; System.out.println("3 match, you won $ "+ tripleWin); System.out.println("You have $ " + newTotal); newTotal++; } else if (spin1 == spin2 || spin2 == spin3 || spin3 == spin1) { double doubleWin; double playerBet; double newTotal; final int DOUBLE = 2; // to calculate winnings for 2 matches doubleWin = playerBet * DOUBLE; /*140: error: variable playerBet might not have been initialized doubleWin = playerBet * DOUBLE;*/ newTotal = playerBet + doubleWin; System.out.println("2 match, you won $ "+ doubleWin); System.out.println("You have $ " + newTotal); newTotal++; } else { System.out.println("None match, you won absolutely nothing."); } } public static boolean playAgain(String yes, String no) { Scanner keyboard = new Scanner(System.in); String playSomeMore; ////String yes; // String no; System.out.println("Play again? Enter yes or no."); playSomeMore = keyboard.nextLine(); if (playSomeMore.equals("yes")) { return true; } else { return false; } }

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!