Copy the file DiceSimulation.java (see Code Listing 4.1) from below these instructions. DiceSimulation.java is incomplete. Since there is a large part of the program missing, the output will be incorrect if you run DiceSimulation.java. I have declared all the variables. You need to add code to simulate rolling the dice and keeping track of the doubles. Convert the algorithm below into Java code and place it in the main method after the variable declarations, but before the output statements. You

1 answer
Question:

Copy the file DiceSimulation.java (see Code Listing 4.1) from below these instructions. DiceSimulation.java is incomplete. Since there is a large part of the program missing, the output will be incorrect if you run DiceSimulation.java. I have declared all the variables. You need to add code to simulate rolling the dice and keeping track of the doubles. Convert the algorithm below into Java code and place it in the main method after the variable declarations, but before the output statements. You will be using several control structures: a while loop and an if-else-if statement nested inside another if Use the indenting of the algorithm to help you decide what is included in the loop, what is included in the if statement, and what is included in the nested if-else-if statement. To "roll" the dice, use the nextInt method of the random number generator to generate an integer from 1 to 6.

Answers

Answer:Program Dice.java=================================================import java.util.Random;public class Dice{ private int spots; //the number of spots up on the die private static Random generator; //a random number generator use simulating rolling dice, //shared by all dice, so that it will be as random as possible //constructor creates a single die, inititally with no spots public Dice() {//create an instance of the random generator = new Random(); spots = 0; } //simulates rolling the die and stores the numbers rolled public void roll() {//return 1,2,3,4,5, or 6 spots = generator.nextInt(6) + 1; } //return the value of the die public int getSpots() { return spots; }}=========================================================Program DiceSimulation.java=========================================================public class DiceSimulation{ public static void main(String [] args) { final int NUMBER = 10000; //the number of times the roll the dice Dice die1 = new Dice(); //first die Dice die2 = new Dice(); //second die int die1Value; //the number of spots on the second die int die2Value; //the number of spots on the first die int count = 0; //number of times the dice were rolled int snakeEye = 0; //number of times of snakes eyes is rolled//number of times double two's, three's, four's, five's, six's int twos = 0; int threes = 0; int fours = 0; int fives = 0; int sixes = 0;//ENTER YOUR CODE FOR THE ALGORITHM HERE for(count=0;count<=NUMBER;count++) { die1.roll(); int t1=die1.getSpots(); die2.roll(); int t2=die2.getSpots(); if(t1==t2) { if(t1==1)snakeEye++; else if(t1==2)twos++; else if(t1==3)threes++; else if(t1==4)fours++; else if(t1==5)fives++; else if(t1==6)sixes++; } } count--;//output to console System.out.println("You rolled snake eyes " + snakeEye + " out of " + count + " rolls."); System.out.println("You rolled double two " + twos + " out of " + count + " rolls."); System.out.println("You rolled double threes " + threes + " out of " + count + " rolls."); System.out.println("You rolled double fours " + fours + " out of " + count + " rolls."); System.out.println("You rolled double fives " + fives + " out of " + count + " rolls."); System.out.println("You rolled double sixes " + sixes + " out of " + count + " rolls."); }}========================================================Sample output:

Similar Solved Questions

1 answer

How many fluid ounces of water does sofia use to make the batch of slime?

how many fluid ounces of water does sofia use to make the batch of slime?...
1 answer

There are 18 boys and 21 girls in the running club. What is the ratio of girls to boys?

There are 18 boys and 21 girls in the running club. What is the ratio of girls to boys?...
2 answers

If you are saying i am going to sun bathe do you say Yo voy a tomar el sol or Yo voy a Tomo el sol

If you are saying i am going to sun bathe do you say Yo voy a tomar el sol or Yo voy a Tomo el sol...
1 answer

Sarah is saving to buy a new phone. She needs $150, and she has already saved $63. Write an equation to model this situation. Let x represent the amount of money Sarah needs. How much money does Sarah need?

Sarah is saving to buy a new phone. She needs $150, and she has already saved $63. Write an equation to model this situation. Let x represent the amount of money Sarah needs. How much money does Sarah need?...
2 answers

What is the great egg drop experiment about?

What is the great egg drop experiment about?...
1 answer

Which Are characteristics of natural selection

Which Are characteristics of natural selection...
1 answer

A number is selected at random from set (2,3,45,6,7,8,9,and 10). which event covers the entire sample space of this experiment ?

a number is selected at random from set (2,3,45,6,7,8,9,and 10). which event covers the entire sample space of this experiment ?...
1 answer

-3.2 < -3 Is this true or false?

-3.2 < -3 Is this true or false?...
1 answer

PLEASE HELP WILL GIVE BRAINLIEST

PLEASE HELP WILL GIVE BRAINLIEST...
2 answers

Can someone help me NOW, please? It's for algebra

Can someone help me NOW, please? It's for algebra...
2 answers

Temperature is a measure of the average ____________ energy of an object's particles.

Temperature is a measure of the average ____________ energy of an object's particles....
2 answers

(3x²-7x+2)+(2x²+7x-1)

(3x²-7x+2)+(2x²+7x-1)...
1 answer

What was obama's previous experience?

What was obama's previous experience?...
1 answer

Ali surveyed his classmates to see who liked tennis. In all, 32 males liked tennis, and 6 males did not like tennis; 13 females liked tennis, and 4 females did not like tennis. How many females did Ali survey

Ali surveyed his classmates to see who liked tennis. In all, 32 males liked tennis, and 6 males did not like tennis; 13 females liked tennis, and 4 females did not like tennis. How many females did Ali survey...
2 answers

Can anybody help me please :(​

can anybody help me please :(​...
1 answer

1 point Identify from the list all of the equations that are equivalent to 9x + 3y = 12 Note: You can select more than one equation. 5y = -15x + 20 y = 3x + 4 3x + y = 4 6x+2y= 8 x+3y=4 Hurry will mark brainliest

1 point Identify from the list all of the equations that are equivalent to 9x + 3y = 12 Note: You can select more than one equation. 5y = -15x + 20 y = 3x + 4 3x + y = 4 6x+2y= 8 x+3y=4 Hurry will mark brainliest...
2 answers

The period of the "five good emperors" was characterized by Select one: A. dynastic succession within the royal line. B. stability and prosperity. C. the establishment of Christianity as the state religion. D. more democratic institutions. E. violent succession.

The period of the "five good emperors" was characterized by Select one: A. dynastic succession within the royal line. B. stability and prosperity. C. the establishment of Christianity as the state religion. D. more democratic institutions. E. violent succession....
1 answer

Which of the following is equivalent to the radical expression below √12x^3

which of the following is equivalent to the radical expression below √12x^3...
2 answers

If your favorite holiday is Christmas and why is it your favorite please use 2 sentences

If your favorite holiday is Christmas and why is it your favorite please use 2 sentences...
2 answers

Hey? how was ur day tell me now!

Hey? how was ur day tell me now!...

-- 0.025360--