/* * Rolls the dice a million times. Keeps track of the number of times * a 2,7,11 and doubles are rolled. * * This class uses class PairOfDice. * * @author Antony Larrain * */ class DiceStats { public static void main( String [] arg){ final int ROLLS = 1000000; PairOfDice dice = new PairOfDice(); int two = 0, seven = 0, eleven = 0, doubles = 0; for(int i = 0; i < ROLLS; i++) { switch(dice.roll()){ case 2: ++two; ++doubles; break; case 7: ++seven; break; case 11: ++eleven; break; default: if(dice.getDie1() == dice.getDie2()) ++doubles; break; } } System.out.println("Number of two's " + (double) two / ROLLS * 100 ); System.out.println("Number of Sevens's " + (double) seven / ROLLS * 100); System.out.println("Number of eleven's " + (double) eleven / ROLLS * 100); System.out.println("Number of doubles " + (double) doubles / ROLLS * 100); } }