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

Using Java Simple Slot Machine Game Create a program, called Assignment2 that pr

ID: 3857453 • Letter: U

Question

Using Java

Simple Slot Machine Game Create a program, called Assignment2 that prompt the user to enter the number of quarters they want to put into the machine. Since this is a prototype, you only need to print out the appropriate word representing the image that would normally be displayed in the slot machine. The program will display the word from the following list of words: Cherries, Oranges, Plums, Bells, Melons, Bars. The program will generate three random numbers each from the range of 0 to 5. Each number will determine which word gets displayed by using the order of the words (e.g., if the number is 0, the displayed word will be "Cherries", if 1, "Oranges" will be displayed, etc.). The program will keep prompting the user for quarters. If the user enters 0, the program will exit. The user starts with $5.00 in quarters. Their remaining balance is also displayed. If the balance drops to zero, the program exits. The payoff rules are as follows: No word matches = $0.00 Two word matches = two times the amount entered Three word matches = three times the amount entered Three "Bars" matches = five times the amount entered Your program shall look like the following: C: > java Assignment2 Enter number of quarters inserted: 2 After spin: Orange Plum Plum You win: $1.00 Your balance: $5.50 Enter number of quarters inserted: 4 After spin: Bars Cherries Orange You win: $0.00 Your balance: $4.50 Enter number of quarters inserted: 3 After spin: Bars Bars Bars You win: $3.75 Your balance: $7.50 Enter number of quarters inserted: 2 After spin: Bells Bells Bells You win: $1.50 Your balance: $8.50 Enter number of quarters inserted: 0 Thanks for playing.

Explanation / Answer

Assignment2.java

import java.util.Random;

import java.util.Scanner;

public class Assignment2 {

public static void main(String[] args) {

Scanner scan = new Scanner(System.in);

String words[] = {"Cherris","Oranges","Plums","Bells","Melons","Bars"};

Random r = new Random();

double balance = 5.0;

System.out.print("Enter number of quarters inserted: ");

int quarters= scan.nextInt();

double win = 0;

while(balance>0 && quarters != 0) {

System.out.print("After spin: ");

String word1 = words[r.nextInt(words.length)];

String word2 = words[r.nextInt(words.length)];

String word3 = words[r.nextInt(words.length)];

System.out.print(word1+" "+word2+" "+word3);

System.out.println();

if(word1.equals("Bars") && word1.equals(word2) && word2.equals(word3)) {

win = 5 * quarters;

}

else if(word1.equals(word2) && word2.equals(word3)) {

win = 3 * quarters;

}

else if(word1.equals(word2) || word2.equals(word3) || word3.equals(word1)) {

win = 2 * quarters;

} else {

win = 0;

balance-=quarters;

}

System.out.println("You win: $"+win+" Your balance: $"+(balance+win));

if(quarters > 0) {

System.out.print("Enter number of quarters inserted: ");

quarters = scan.nextInt();

}

}

System.out.println("Thanks for playing.");

}

}

Output:

Enter number of quarters inserted: 2
After spin: Bells Plums Bells
You win: $4.0 Your balance: $9.0
Enter number of quarters inserted: 3
After spin: Oranges Bars Cherris
You win: $0.0 Your balance: $2.0
Enter number of quarters inserted: 1
After spin: Bars Plums Cherris
You win: $0.0 Your balance: $1.0
Enter number of quarters inserted: 2
After spin: Cherris Bells Bells
You win: $4.0 Your balance: $5.0
Enter number of quarters inserted: 5
After spin: Bars Oranges Oranges
You win: $10.0 Your balance: $11.0
Enter number of quarters inserted: 11
After spin: Cherris Bells Cherris
You win: $22.0 Your balance: $23.0
Enter number of quarters inserted: 0

Thanks for playing.

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