In: Computer Science
You are to write a program using Java that will simulate a slot machine with four wheels. It will determine the amount of money won for each spin. The four wheels spin and stop showing a value between 0 and 9 inclusive. It costs $2 to play.
•You win $500 (but not the $2 you bet) if you get 4 wheels the same.
•You win $10 (but not the $2 you bet) if you get exactly 3 of a kind.
•You win $5 (but not the $2 you bet) if you get two pairs.
•You win $2 if you get 2 wheels the same (That is, you break even).
•You win nothing and lose your $2 bet if you get no matches.
Your program must use 4 methods:
1.One to randomly generate the 4 wheel values.
2.One to output the result of the spin.
3.One to compute the win or loss and print the correct message
4.Finally, one to output new balance and a nice line break graphic as seen below.
Input and Output:Your program will randomly generate a starting balance between $100 and $200 inclusive. Your program will randomly generate four integers (1 for each wheel).Your program will output a description of the input combination and the amount you won or lost.Your program will output your new balance after each spin.
Please help
Please find below code and refer screenshot for output.
This code does result after 1 spin of 4wheels
Code:
import java.util.Random;
public class Main
{
public static void main(String[] args) {
int wheel1,wheel2,wheel3,wheel4;
int starting_balance;
int min=100;
int max=200;
int lost=0,credit=0;
starting_balance=min+(int)(Math.random()*((max-min)+1));
System.out.println("starting
balance is "+starting_balance);
wheel1=get_wheel_value();
wheel2=get_wheel_value();
wheel3=get_wheel_value();
wheel4=get_wheel_value();
System.out.println("The wheels
values are "+wheel1+" "+wheel2+" "+wheel3+" "+wheel4);
starting_balance-=2;
lost+=2;
if((wheel1==wheel2)&&(wheel2==wheel3)&&(wheel3==wheel4)){
starting_balance+=500;
credit+=500;
}
else
if(((wheel1==wheel2)&&(wheel1==wheel3))||((wheel2==wheel3)&&(wheel2==wheel4))||((wheel3==wheel4)&&(wheel3==wheel1))||((wheel1==wheel3)&&(wheel1==wheel4))){
starting_balance+=10;
credit+=10;
}
else
if(((wheel1==wheel2)&&(wheel3==wheel4))||((wheel1==wheel3)&&(wheel2==wheel4))||((wheel1==wheel4)&&(wheel2==wheel3))){
starting_balance+=5;
credit+=5;
}
else
if((wheel1==wheel2)||(wheel1==wheel3)||(wheel1==wheel4)||(wheel2==wheel3)||(wheel2==wheel4)||(wheel3==wheel4)){
starting_balance+=2;
credit+=2;
}
System.out.println("The result of
the spin, total credit is "+credit+" and total loss is
"+lost);
System.out.println("Current balance
is "+starting_balance);
}
public static int get_wheel_value(){
int value;
int min=0;
int max=9;
value=min+(int)(Math.random()*((max-min)+1));
return value;
}
}
Output: