All pastes #362746 Raw Edit

jafari

public java v1 · immutable
·published 2007-02-19 00:49 UTC
rendered paste body
public class DiceRollStats2 {        static final int NUMBER_OF_EXPERIMENTS = 10000;        private static PairOfDice dice = new PairOfDice();                         public static void main(String[] args) {            TextIO.putln("Dice Total   Avg # of Rolls   Stand. Deviation   Max # of Rolls");            TextIO.putln("----------   --------------   ----------------   --------------");            for ( int total = 2;  total <= 12;  total++ ) {               StatCalc stats;  // An object that will compute the statistics.               stats = new StatCalc();               for ( int i = 0; i < NUMBER_OF_EXPERIMENTS; i++ ) {                                       stats.enter( rollFor(total) );               }               TextIO.put(total, 6);               TextIO.put(stats.getMean(), 18);               TextIO.put(stats.getStandardDeviation(), 19);               TextIO.put(stats.getMax(), 14);               TextIO.putln();            }        } // end main        static int rollFor( int N ) {                             int rollCt = 0;  // Number of rolls made.            do {               dice.roll();               rollCt++;            } while ( dice.getTotal() != N );            return rollCt;        }     }  // end class DiceRollStats2