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

Create a program that simulates a slot machine. When the program runs, it should

ID: 3677469 • Letter: C

Question

Create a program that simulates a slot machine. When the program runs, it should do the following: Asks the user to enter the amount of money he or she wants to enter into the slot machine. The amount entered into the slot machine MUST be between 5 and 100. If the user enters an amount outside this range, he or she should be prompted to re-enter the amount again. If the user fails to enter a valid amount in three consecutive attempts, the game should be terminated, with the message “ Oops! Valid Amount Not Entered. Game Terminated”.

Explanation / Answer

import java.util.Random;

import java.util.Scanner;

public class SlotMachine

{

public static void main(String[] args)

{

//declaring variables and initializing variables

int Cherries= 0,oranges=1,plums=2,bells=3,melons = 4,bars=5,c=1;

//declaring variables

int betam,choice1,choice2,choice3,counter;

String playagain;

//creating objet for Random class implementing randomIntegers interface

//For generating random numbers

Random randomIntegers = new Random();

Scanner keyboard = new Scanner(System.in);

While(true)

{

//Asking bet amount from user

while(true)

{

System.out.println("Enter your bet amount between 5 and 100");

bet = keyboard.nextInt();

if(bet>5 && bet<100)

return true;

else

{

c++;

return false;

}

if(c==3)

{

System.out.println("Oops! Valid Amount Not Entered. Game Terminated");

System.exit(0);//exiting java program

}

System.out.println("Enter your first choice");

choice1 = keyboard.nextInt();

System.out.println("Enter your second choice");

Choice2 = keyboard.nextInt();

System.out.println("Enter your third choice");

Choice3 = keyboard.nextInt();

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

{

switch(randomIntegers.nextInt(5))

{

case 0: System.out.println("Cherry"+ " " + "=$" + 0);

break;

case 1: System.out.println("Orange"+ " " + "=$" + 1);

break;

case 2: System.out.println("Plum"+ " " + "=$" + 2);

break;

case 3: System.out.println("Bell"+ " " + "=$" + 3);

break;

case 4: System.out.println("Melon"+ " " + "=$" + 4);

break;

case 5: System.out.println("Bar"+ " " + "=$" + 5);

break;

for(i=o,i<=3,i++)

{

// Prompt user if they want to play again

System.out.println("Would you like to enter another bet?");

System.out.println("Enter y for yes or n for no.");

  if (playAgain.equals("y"))

return false;

else

{

System.out.print("Thank you for playing.");

System.out.print("Your total winnings is :$");

}//else

}//while

}//main

}//class

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