For this assignment you are adding functionality to a slot machine simulation to
ID: 3605575 • Letter: F
Question
For this assignment you are adding functionality to a slot machine simulation to make it more like a real slot machine using netbeans/java. you need to include clear comments throughout the program that explain what functionality the various lines/small sections of code/methods are as related to the execution of the program.:
-The user begins with a balance of $20
-Each spin costs $1 (note: the first spin should happen automatically)
-If the user gets 2 numbers the same, s/he wins $2 (provide feedback)
-If the user gets all 3 numbers the same, s/he wins $25 (provide feedback)
-After each spin (and balance update), the user’s balance needs to be printed to the screen and formatted as currency prior to asking him/her if s/he would like to spin again
-The program needs to end when the user no longer has an adequate balance to spin again (less than $1)
-When the program ends, print a thank you message to the user.
-Once the program has ended, print a message to the user to pick up his/her winnings if his/her balance is greater than $1; include the balance in the message.
Sample output from the start of the program
Sample output from the end of the program (user has a positive balance)
Sample output from the end of the program (user runs out of money)
Explanation / Answer
import java.util.Random;
import java.util.Scanner;
import java.io.*;
public class Main {
public static void main(String... aArgs){
Random randomGenerator = new Random();
Scanner sc = new Scanner(System.in);
int randomInt1, randomInt2, randomInt3, bal;
bal = 20;
System.out.print("--------------Welcome to Sue's Slot Machine!-------------- Each spin costs $1. Get 2 numbers the same, add $2. Get a jackpot (all three numbers the same) and you win $25. Your starting balance is $20.00 ");
System.out.println("---------------SPINNING-----------------");
randomInt1 = randomGenerator.nextInt(100);
randomInt2 = randomGenerator.nextInt(100);
randomInt3 = randomGenerator.nextInt(100);
System.out.println(" |----|----| | "+randomInt1+" | "+randomInt2+" | "+randomInt3+" | |----|----|");
bal -= 1;
if(randomInt1 == randomInt2 || randomInt1 == randomInt3 || randomInt2 == randomInt3){
bal += 2;
}else if(randomInt1 == randomInt2 && randomInt1 == randomInt3 && randomInt2 == randomInt3){
bal += 25;
}
while(bal > 0){
System.out.println("Do you want to spin again(y/n): ");
String c = sc.nextLine();
if (c == "y" || c == "Y"){
System.out.println("---------------SPINNING-----------------");
randomInt1 = randomGenerator.nextInt(100);
randomInt2 = randomGenerator.nextInt(100);
randomInt3 = randomGenerator.nextInt(100);
System.out.println(" |----|----| | "+randomInt1+" | "+randomInt2+" | "+randomInt3+" | |----|----|");
bal -= 1;
if(randomInt1 == randomInt2 || randomInt1 == randomInt3 || randomInt2 == randomInt3){
bal += 2;
}else if(randomInt1 == randomInt2 && randomInt1 == randomInt3 && randomInt2 == randomInt3){
bal += 25;
}
}else{
System.out.println(" Thanks for playing my Slot Machine! Please pick up your $."+ bal +" winnings from the cashier.");
break;
}
}
if(bal == 0){
System.out.println( "Your current balance is $0.00 Sorry, you have run out of money... Thanks for playing my Slot Machine!");
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.