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
An ice hockey player is skating on an ice rink. The rink has a coefficient of kinetic friction of roughly 0.1. If the normal for
AlekseyPX

Answer:yes

Explanation:he divided by the numnebr of hockey pucks

3 0
3 years ago
Do any of you have an email to contact brainly support? The contact us does not seem to work. Thanks!
Marysya12 [62]

Answer:

I think that if you go to the settings page, there should be a "contact us" option.

Hope this helped!!  :)

3 0
3 years ago
A loss in value caused by an undesirable or hazardous influence offsite is which type of depreciation?
Lubov Fominskaja [6]

External depreciation may be defined as a loss in value caused by an undesirable or hazardous influence offsite.

<h3>What is depreciation?</h3>

Depreciation may be defined as a situation when the financial value of an acquisition declines over time due to exploitation, fray, and incision, or obsolescence.

External depreciation may also be referred to as "economic obsolescence". It causes a negative influence on the financial value gradually.

Therefore, it is well described above.

To learn more about Depreciation, refer to the link:

brainly.com/question/1203926

#SPJ1

5 0
2 years ago
What is digital communication?​
mart [117]

Answer:

Any exchange of data that transmits the data in a digital form is a digital communication.

4 0
3 years ago
1. You use
lorasvet [3.4K]
4-ways tell me if I’m wrong
4 0
3 years ago
Other questions:
  • In an air standard diesel cycle compression starts at 100kpa and 300k. the compression ratio is 16 to 1. The maximum cycle tempe
    11·1 answer
  • Thermoplastics burn upon heating. a)-True b)- false?
    14·1 answer
  • For turbulent now the friction factor is function of (Reynolds number —surface roughness -both the Reynolds number and the surfa
    10·1 answer
  • This is a classification of back pain based on duration. A) AcuteB) RecurrentC) ChronicD) All of the above
    11·1 answer
  • Implement
    14·1 answer
  • The pressure distribution over a section of a two-dimensional wing at 4 degrees of incidence may be approximated as follows: Upp
    9·1 answer
  • "Carbon 14 (C-14), a radioactive isotope of carbon, has a half-life of 5730 ± 40 years. Measuring the amount of this isotope lef
    12·1 answer
  • The wall of an oven used to cure plastic parts is of thickness L = 0.05 m and is exposed to large surroundings and air at its ou
    14·1 answer
  • What is the correct order of the different environments from coldest to hottest?
    12·2 answers
  • Routers cannot be used to cut through material.<br><br> True<br> False
    15·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!