Question

In: Computer Science

You are to write a program using Java that will simulate a slot machine with four...

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

Solutions

Expert Solution

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:


Related Solutions

Java - Create a program that simulates a slot machine. When the program runs, it should...
Java - Create a program that simulates a slot machine. When the program runs, it should do the following: - Ask the user to enter the amount of money he or she wants to enter into the slot machine. - Instead of displaying images, have the program randomly select a word from the following list: Cherries, Oranges, Plums, Bells, Melons, Bars (To select a word, the program can generate a random number in the range of 0 through 5. If...
Java 176 Lottery Program in Word. Using ArrayLists to Simulate a Lottery Program Simulate a Lottery...
Java 176 Lottery Program in Word. Using ArrayLists to Simulate a Lottery Program Simulate a Lottery Drawing by choosing 7 numbers at random from a pool containing 30 numbers Each time a number is selected, it is recorded and removed from the pool The pool values are 00 to 29 inclusive Your program must output each selected number from the drawing using a two-digit format. For Example, the number 2 would be represented by 02 on the “Picked” line. The...
Java: Using ArrayLists to Simulate a Lottery Program Simulate a Lottery Drawing by choosing 7 numbers...
Java: Using ArrayLists to Simulate a Lottery Program Simulate a Lottery Drawing by choosing 7 numbers at random from a pool containing 30 numbers Each time a number is selected, it is recorded and removed from the pool The pool values are 00 to 29 inclusive Your program must output each selected number from the drawing using a two-digit format. For Example, the number 2 would be represented by 02 on the “Picked” line.    The numbers drawn cannot repeat Sort...
In Java, Write a Java program to simulate an ecosystem containing two types of creatures, bears...
In Java, Write a Java program to simulate an ecosystem containing two types of creatures, bears and fish. The ecosystem consists of a river, which is modeled as a relatively large array. Each cell of the array should contain an Animal object, which can be a Bear object, a Fish object, or null. In each time step, based on a random process, each animal either attempts to move into an adjacent array cell or stay where it is. If two...
Part1: Write a program in Java to simulate CPU scheduling using (i) Shortest Job First (both...
Part1: Write a program in Java to simulate CPU scheduling using (i) Shortest Job First (both preemptive and non-preemptive) and (ii)Priority scheduling Go through the related text and implement each of these CPU algorithms. Consider arrival time, CPU burst time and priority given for each of the processes. Show the results of different steps of your implementation. Part2: Draw the Gantt Chart and compute Average Waiting Time and Average Turn Around Time in each case
Using a (GUI interface), write a Java program that simulates an ATM machine with the following...
Using a (GUI interface), write a Java program that simulates an ATM machine with the following options menu: "Welcome" 1. Deposit to account 2. Withdraw 3. Exit
Write a Java program to simulate the rolling of two dice. The application should use an...
Write a Java program to simulate the rolling of two dice. The application should use an object of class Random once to roll the first die and again to roll the second die. The sum of the two values should then be calculated. Each die can show an integer value from 1 to 6, so the sum of the values will vary from 2 to 12. Your application should roll the dice 36,000,000 times. Store the results of each roll...
please write in c using linux or unix Write a program that will simulate non -...
please write in c using linux or unix Write a program that will simulate non - preemptive process scheduling algorithm: First Come – First Serve Your program should input the information necessary for the calculation of average turnaround time including: Time required for a job execution; Arrival time; The output of the program should include: starting and terminating time for each job, turnaround time for each job, average turnaround time. Step 1: generate the input data (totally 10 jobs) and...
Please write in C using linux or unix. Write a program that will simulate non -...
Please write in C using linux or unix. Write a program that will simulate non - preemptive process scheduling algorithm: First Come – First Serve Your program should input the information necessary for the calculation of average turnaround time including: Time required for a job execution; Arrival time; The output of the program should include: starting and terminating time for each job, turnaround time for each job, average turnaround time. Step 1: generate the input data (totally 10 jobs) and...
For this assignment you will write a Java program using a loop that will play a...
For this assignment you will write a Java program using a loop that will play a simple Guess The Number game. Create a new project named GuessANumber and create a new Java class in that project named GuessANumber.java for this assignment. The program will randomly generate an integer between 1 and 200 (including both 1 and 200 as possible choices) and will enter a loop where it will prompt the user for a guess. If the user has guessed the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT