1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
MariettaO [177]
3 years ago
6

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.

Engineering
1 answer:
Aliun [14]3 years ago
5 0

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:

You might be interested in
A good rule of thumb is to design the horizontal stabilizer so that its area is about 1/6 to 1/8 of the area of the wing. If the
erik [133]

Answer:

Stabilizer with area = 14 cm2

Explanation:

i dont know why but its right

4 0
3 years ago
When you see a street with white markings only, what kind of street is it?
Georgia [21]

Answer:

it's a one way street

3 0
4 years ago
Just to let you know Christmas is in 10 days&lt;3<br><br> lol
Harrizon [31]

Answer:

yay yay

Explanation:

im so excited i cant wait

7 0
3 years ago
Read 2 more answers
Three methods by which the value of the unknown resistance can be determined​
Contact [7]

Answer:

The Meter bridge is the modification of Wheatstone's network used to determine the value of unknown resistance. The meter bridge consists of a thin, uniform, and homogenous conducting wire AC, rectangular wooden board between two thick L shaped metal strips C1 and C2 as shown in the diagram.

5 0
3 years ago
What differentiates an athletic trainer from a clinical exercise physiologist?
kozerog [31]

Answer:

It's number 3

Explanation:

3 0
3 years ago
Read 2 more answers
Other questions:
  • Air flows steadily through a variable sized duct in a heat transfer experiment with a speed of u = 20 – 2x, where x is the dista
    10·1 answer
  • .provide feedback to the controller about the robot's environment, a limited sense of sight and sound
    6·2 answers
  • Social engineering
    12·1 answer
  • Select all of the true statements.
    14·1 answer
  • An engine indicator is used to determine the following: (a) speed (d) m.e.p, and IHP (e) BHP (b) temperature (c) volume of cylin
    7·1 answer
  • Which of the following is a advantage of a chain and sprocket over a pulley and belt system?
    7·1 answer
  • Gold forms a substitutional solid solution with silver. Calculate the number of gold atoms per cubic centimeter (in atoms/cm3) f
    15·1 answer
  • Consider a simple ideal Rankine cycle with fixed boiler and condenser pressures. If the steam is superheated to a higher tempera
    8·1 answer
  • The value of universal gas constant is same for all gases?<br> a) yes<br> b)No
    15·1 answer
  • Pls pls pls pls plsss someone help pls
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!