//************************************************ // Program Name: pairofdice.java * // Author: Pat Moss * // Date: Oct 10, 2005 Rev: 01 * // * // Demonstrate the class pairofdice, etc. * //************************************************ // Represent two dice with faces showing values // between 1 and 6 // A composite value is returned in the form: // result = die1.faceValue * 10 + die2.faceValue // So, for example, // if die1.faceValue = 3 and die2.faceValue = 5 // then the composite integer result returned is 35 public class pairofdice { private final int SIX = 6; // maximum face value private int faceValue1; // current value for die1 private int faceValue2; // current value for die2 private int bothValues; // composite value for both // declare and initialize the two dice objects onedie die1 = new onedie(SIX); onedie die2 = new onedie(SIX); // Constructor: Set the initial composite value // for the sum bothValues public pairofdice() { faceValue1 = die1.getFaceValue(); faceValue2 = die2.getFaceValue(); bothValues = faceValue1 * 10 + faceValue2; } // roll both dice and return the composite result public int throwdice() { faceValue1 = die1.roll(); faceValue2 = die2.roll(); bothValues = faceValue1 * 10 + faceValue2; return bothValues; } // return a string representation of the composite result public String toString() { String result = Integer.toString(bothValues); return result; } }