Question: In this program that I put you have to correct and apply a DO while lopp. /** This class simulates rolling a pair of dice
In this program that I put you have to correct and apply a DO while lopp.




/** This class simulates rolling a pair of dice 10,000 times and counts the number of times doubles of are rolled for each different pair of doubles. */
import java.util.Random; //to use the random number generator public class DiceSimulation { public static void main(String[] args) { final int NUMBER = 10000; //the number of times to roll the dice
//a random number generator used in simulating rolling a dice Random generator = new Random(); int die1Value; // number of spots on the first die int die2Value; // number of spots on the second die int count = 0; // number of times the dice were rolled int snakeEyes = 0; // number of times snake eyes is rolled int twos = 0; // number of times double two is rolled int threes = 0; // number of times double three is rolled int fours = 0; // number of times double four is rolled int fives = 0; // number of times double five is rolled int sixes = 0; // number of times double six is rolled
//ENTER YOUR CODE FOR THE ALGORITHM HERE
System.out.println ("You rolled snake eyes " + snakeEyes + " out of " + count + " rolls."); System.out.println ("You rolled double twos " + 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."); } }
1. Change the while loop to a do-while loop. Compile and run. You should get the same results. Introduction This is a simulation of rolling dice. Actual results approach theory only when the sample size is large. So we will need to repeat rolling the dice a large number of times (we will use 10,000). The theoretical probability of rolling doubles of a specific number is 1 out of 36 or approximately 278 out of 10,000 times that you roll the pair of dice. Since this is a simulation, the numbers will vary a little each time you run it. Check out how to use the random number generator (introduced in section 4.11 of the text) to get a number between 1 and 6 to create the simulation. We will continue to use control structures that we have already learned, while exploring control structures used for repetition. We shall also continue our work with algorithms, translating a given algorithm to java in order to complete our program. We will start with a while loop, then use the same program, changing the while loop to a do-while loop, and then a for loop. We will be introduced to file input and output. We will read a file, line by line, converting each line into a number. We will then use the numbers to calculate the mean and standard deviation. First we will learn how to use file output to get results printed to a file. Next we will use file input to read the numbers from a file and calculate the mean. Finally, we will see that when the file is closed, and then reopened, we will start reading from the top of the file again so that we can calculate the standard deviation
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
