I'm in my second quarter of a Java class in which we recently had a project. The project was to be to create a dice simulation in which two die are taken and rolled, the frequencies of the sums are randomly generated, an empirical distribution (in decimals) is taken from the frequencies, an exact distribution (in decimals) is made before hand and tested for, and and then the error is recorded by subtracting Exact from the Empirical (i.e 0.0279 - .02777 = ERROR).
The code segment that we were given: (apparently from a Princeton java book)
int SIDES = 6;
double[] dist = new double[2*SIDES+1];
for(int i = 1; i <= SIDES; i++)
{
for(int j = 1; j <= SIDES; j++)
{
dist[i+j] += 1.0;
}
for(int k = 2; k <= 2*SIDES; k++)
{
dist[k] /= 36.0;
}
The exact assignment we were given is this: The value dist[k] is the probability that the dice sum to k. Run experiments to validate this calculation simulating N dice throws, keeping track of the frequencies of occurrence of each value when you compute the sum of two random integers between 1 and 6.
This assignment was poorly explained by our teacher, who did little to simplify it for us. Despite the assignment asking for N times (implying some form of input from the user) instead we were told that this program would be run from the command line but there would be no form of input by the user and the number of frequencies would be randomly generated.
Such As:
c:\Users\NAME\Desktop\Assgn>javac dice.java
c:\Users\NAME\Desktop\Assgn>java dice
Then the program prints out such as:
No one in my class was really able to solve this assignment and my teacher thankfully dropped it. Can anybody code this out(+comments) and post it so I can at least know how to do this assignment?
Aucun commentaire:
Enregistrer un commentaire