// 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 countof12, dievalue1, dievalue2; private Dice die1, die2; public Rollem ( ) { countof12 = dievalue1 = dievalue2 = 0; die1 = new Dice ( ); die2 = new Dice ( ); } public static void main ( String [] args ) { Rollem r = new Rollem ( ); r.RollThoseDice ( ); r.PrintResult ( ); } public void RollThoseDice ( ) { int count = 0; while ( count < 1000 ) { count++; dievalue1 = die1.Roll ( ); dievalue2 = die2.Roll ( ); System.out.println ( " " + dievalue1 + " " + dievalue2 ); if ( dievalue1 + dievalue2 == 12 ) countof12++; } } public void PrintResult ( ) { System.out.println ( "\n\nThe sum of 6 was rolled " + countof12 + " times." ); System.out.println ( "\n\nYou rolled the dice " + die1.SendRollCount ( ) + " times.\n\n" ); } }