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

C++ LANGUAGE!!!! Create a program that simulates a slot machine. When the progra

ID: 3845026 • Letter: C

Question

C++ LANGUAGE!!!!

Create a program that simulates a slot machine. When the program runs it should do the following:

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

2. Instead of displaying images, have the program display the name of the image. The program must randomly select a word from the following list:
Cherries, Oranges, Plums, Bells, Melons, Bars


To select a word, the program can generate a random number in the range of 0 to 5. If the number is 0, the selected word is Cherries, if the number is 1, then the selected word is Oranges, and so forth. The program should randomly select a word from the list 3 times and display all 3 of the words.


3. If none of the randomly selected words match, the program informs the user that he or she has won $0. If 2 of the words match, the program informs the user of the amount (2 times the amount entered) that he or she has won. If 3 of the words match, the program informs the user of the amount (3 times the amount entered) that he or she has won.

The program Runs Repeatedly until the user says NO.

You can define a function to generate the word in the list, another function to compare the three slots and display proper message. Then call those functions in the main function.

Explanation / Answer

import java.util.Scanner;

import java.util.Random;

public class SlotMachineHWCH6

{

public static void Main(String[] args)

{

Scanner keyboard = new Scanner(System.in);

string slotMachine;  

double initialPlayerBet;

double playerBet = 0;

double totalPlayerBets;

double totalWinnings = 0;  

double tripleWin = 0;  

double doubleWin = 0;  

String spin, spin1, spin2, spin3;   

int i;                  

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)

while (keepPlaying)

{

System.out.println("Enter your bet");

playerBet = keyboard.nextDouble();

for (i = 1; i <= 3; i++)

{      

getSlotItems(spin); /*error: variable spin might not have been initialized*/

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);

playAgain(yes, no);

playAgain(yes, no);

}

}

public static String getSlotItems(String spin)

{

Random rand = new Random(); //random number generator

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;  

tripleWin = playerBet

tripleWin = playerBet * TRIPLE;

double playerBet;

double newTotal;

final int TRIPLE = 3;

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;

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;

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Chat Now And Get Quote