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
2. When it comes to selling their crop, what are 3 options a farmer has when harvesting their grain?
tiny-mole [99]

Answer:

Sell his crop, use his crop as food, and sell his crop

Explanation:

6 0
3 years ago
Briefly explain how a jet moves
sergejj [24]

Answer:

Jet engines move the airplane forward with a great force that is produced by a tremendous thrust and causes the plane to fly very fast. All jet engines, which are also called gas turbines, work on the same principle. The engine sucks air in at the front with a fan. ... Spinning the turbine causes the compressor to spin.

Explanation:

yw

8 0
3 years ago
A pipeline (NPS = 14 in; schedule = 80) has a length of 200 m. Water (15℃) is flowing at 0.16 m3/s. What is the pipe head loss f
dangina [55]

Answer:

Head loss is 1.64

Explanation:

Given data:

Length (L) = 200 m

Discharge (Q) = 0.16 m3/s

According to table of nominal pipe size , for schedule 80 , NPS 14,  pipe has diameter (D)= 12.5 in or 31.8 cm 0.318 m

We know, head\ loss  = \frac{f L V^2}{( 2 g D)}

where, f = Darcy friction factor

V = flow velocity

g = acceleration due to gravity

We know, flow rate Q = A x V

solving for V

V = \frac{Q}{A}

    = \frac{0.16}{\frac{\pi}{4} (0.318)^2} = 2.015 m/s

obtained Darcy friction factor  

calculate Reynold number (Re) ,

Re = \frac{\rho V D}{\mu}

where,\rho = density of water

\mu = Dynamic viscosity of water at 15 degree  C = 0.001 Ns/m2

so reynold number is

Re = \frac{1000\times 2.015\times 0.318}{0.001}

            = 6.4 x 10^5

For Schedule 80 PVC pipes , roughness (e) is  0.0015 mm

Relative roughness (e/D) = 0.0015 / 318 = 0.00005

from Moody diagram, for Re = 640000 and e/D = 0.00005 , Darcy friction factor , f = 0.0126

Therefore head loss is

HL = \frac{0.0126 (200)(2.015)^2}{( 2 \times 9.81 \times 0.318)}

HL = 1.64 m

7 0
4 years ago
- WHEN YOU ARE TOWING A TRAILER:
zheka24 [161]

Answer:

And Im still going with B..

7 0
3 years ago
Is it true or false that sometimes people except certain risks in exchange for other benefits
mixas84 [53]
Yes, they have to make certain sacrifices ! for many many benefits.
3 0
3 years ago
Other questions:
  • Water flows through a horizontal plastic pipe with a diameter of 0.15 m at a velocity of 15 cm/s. Determine the pressure drop pe
    11·1 answer
  • A heat engine does 210 J of work per cycle while exhausting 440 J of waste heat. Part A What is the engine's thermal efficiency?
    6·1 answer
  • How to go about the designing of a multirange voltmeter​
    8·1 answer
  • Read a 4 character number. Output the result in in the following format, Input 9873, Output 3 *** 7 ******* 8 ******** 9 *******
    8·1 answer
  • In dynamics, the friction force acting on a moving object is always a) in the same direction of its motion b) a kinetic friction
    15·1 answer
  • How many trains have been invented all around the world?
    14·1 answer
  • The website of a bank that an organization does business with has been reported as untrusted by the organization's web browser.
    12·1 answer
  • Quản trị học là gì ? ý nghĩa của quản trị học với thực tế xã hội
    10·1 answer
  • A spherical metal ball of radius r_0 is heated in an oven to a temperature of T_1 throughout and is then taken out of the oven a
    6·1 answer
  • A building permit allows a builder to?
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!