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.
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:
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?...
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...
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...
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....