1 2 3 /*10.1 4 * Model a die in terms of two properties: 5 * - order, the number of faces 6 * - top, the value of the top face 7 */ 8 9 package chance; 10 11 public class Die { 12 13 // THE INSTANCE VARIABLES (STATE) 14 15 private int order; 16 private int top; 17 18 // THE CONSTRUCTORS 19 20 public Die(){ 21 order = 6; 22 top = (int)((Math.random() * 6) + 1); 23 } 24 25 public Die(int nrOfSides){ 26 order = nrOfSides; 27 top = (int)((Math.random() * nrOfSides) + 1); 28 } 29 30 // THE METHODS (BEHAVIOR) 31 32 public int top(){ 33 return top; 34 } 35 36 public void roll(){ 37 top = (int)((Math.random() * order) + 1); 38 } 39 40 }