- Ask the user to enter the amount of money he or 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.
- If none of the randomly selected words match, the program will inform the user that he or she has won $0. If two of the words match, the program will inform the user that he or she has won two times the amount entered. If three of the words match, the program will inform the user that he or 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.
----------------------------------------------------------------------------------------------------------------------
I can't seem to figure out how to get it to repeat and display the amount they have won after they enter their bet. Any help would be great. Thank you in advance.
This is what I have so far:
import java.util.Random;
import java.util.Scanner;
public class SlotMachine
{
public static void main(String[] args)
{
// Create a Random object. This object will
// provide us with the random integer.
Random randomIntegers = new Random();
Scanner keyboard = new Scanner(System.in);
// Declare variables
int Cherries = 0;
int Oranges = 1;
int Plums = 2;
int Bells = 3;
int Melons = 4;
int Bars = 5;
int counter;
int bet;
int firstChoice;
int secondChoice;
int thirdChoice;
// Prompt user for bet
System.out.println("Enter your bet amount");
bet = keyboard.nextInt();
System.out.println("Enter your first choice");
firstChoice = keyboard.nextInt();
System.out.println("Enter your second choice");
secondChoice = keyboard.nextInt();
System.out.println("Enter your third choice");
thirdChoice = keyboard.nextInt();
for (counter = 1; counter <=3; counter++)
// Perform the selected operation.
switch(randomIntegers.nextInt(5))
{
case 0:
System.out.println("Cherry"+ "\t" + "=$" + 0);
break;
case 1:
System.out.println("Orange"+ "\t" + "=$" + 1);
break;
case 2:
System.out.println("Plum"+ "\t" + "=$" + 2);
break;
case 3:
System.out.println("Bell"+ "\t" + "=$" + 3);
break;
case 4:
System.out.println("Melon"+ "\t" + "=$" + 4);
break;
case 5:
System.out.println("Bar"+ "\t" + "=$" + 5);
break;
}
}
}

New Topic/Question
Reply



MultiQuote



|