// Scott DeRuiter 6/28/2002 // Dice.java // Creates a Dice that can be used in other programs public class Dice { private int numsides; private int rollcount; public Dice ( ) { numsides = 6; rollcount = 0; } public Dice ( int num ) { numsides = num; rollcount = 0; } public int roll ( ) { rollcount++; return (int)(1 + numsides * Math.random ( )); } public void printRollCount ( ) { System.out.println ( "\nThe dice has been rolled " + rollcount + " times\n\n" ); } public int sendRollCount ( ) { return rollcount; } } // Scott DeRuiter 7/5/2002 // Rollem.java // Roll 2 die 1000 time and see how many time we get a sum of 6. public class Rollem { private int counter, dievalue1, dievalue2; private Dice die1, die2; public Rollem ( ) { counter = dievalue1 = dievalue2 = 0; die1 = new Dice ( ); die2 = new Dice ( ); } public static void main ( String [] args ) { Rollem r = new Rollem ( ); r.rollAll ( ); } public void rollAll ( ) { for ( int sum = 2; sum <= 12; sum++ ) { counter = 0; rollThoseDice ( sum ); } } public void rollThoseDice ( int value ) { int count = 0; while ( count < 1000 ) { count++; dievalue1 = die1.roll ( ); dievalue2 = die2.roll ( ); // System.out.println ( " " + dievalue1 + " " + dievalue2 ); if ( dievalue1 + dievalue2 == value ) counter++; } printResult ( value ); } public void printResult ( int value ) { System.out.println ( "\n\nThe sum of " + value + " was rolled " + counter + " times." ); } }