Write a program that computes the mean and standard deviation for a sample of 1,000 values. Your program will generate the 1,000 values using the Die class and your program must print the computed mean and standard deviation.

We shall use the definition for the standard deviation, given in wikipedia, for a set of N values :

s = \sqrt{\frac{1}{N-1} \sum_{i=1}^N (x_i - \overline{x})^2}\,,

\scriptstyle\{x_1,\,x_2,\,\ldots,\,x_N\} is the sample of N values and \scriptstyle\overline{x} is the mean (average) of the sample.

You can generate the 1,000 values using the Die class... instantiate a die with 20 sides and then toss it 1,000 times, saving those values in an array. Use a seed of 101 ... this guarantees everyone has the same "random" numbers and this allows you to compare your final result with your colleagues. Consider :

public Die(int numberSides)
        // initialize instance variables
        this.numberSides = numberSides;
        generator = new Random();
        // use the same seed each time
        // so the results will be the same for everyone

Write separate value-returning methods that calculate the mean and standard deviation.

I really don't have a clue how to proceed.

Edited by peter_budo: Keep IT Organized - For easy readability, always wrap programming code within posts in [code] (code blocks)

7 Years
Discussion Span
Last Post by ithelp
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.