Task #1 The while Loop (8 pts)
1. Copy the file DiceSimulation.java as directed by your instructor. Correct syntax errors, if any,
and improve programming style when necessary (indents, newlines, etc.). DiceSimulation.java is
incomplete. Since there is a large part of the program missing, the output will be incorrect if you
run DiceSimulation.java.
2. We 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 statement. 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 isincluded in the nested if-else-if statement.
3. To “roll” the dice, use the nextInt method of the random number generator to generate an
integer from 1 to 6.
Repeat while the number of dice rolls are less than the number of times the dice should be rolled.
Get the value of the first die by “rolling” the first die
Get the value of the second die by “rolling” the second die
If the value of the first die is the same as the value of the second die
If value of first die is 1
Increment the number of times snake eyes were rolled
Else if value of the first die is 2
Increment the number of times twos were rolled
Else if value of the first die is 3
Increment the number of times threes were rolled
Else if value of the first die is 4
Increment the number of times fours were rolled
Else if value of the first die is 5
Increment the number of times fives were rolled
Else if value of the first die is 6
Increment the number of times sixes were rolled
Page 3 of 3
Increment the number of times the dice were rolled
4. Compile and run. You should get numbers that are somewhat close to 278 for each of the
different pairs of doubles. Run it several times. You should get different results than the first
time, but again it should be somewhat close to 278.