1 package chance; 2 3 /* 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 public class Die { 10 // THE INSTANCE VARIABLES (STATE) 11 12 private int order; 13 private int top; 14 15 // THE CONSTRUCTORS 16 17 public Die() 18 { 19 order = 6; 20 top = (int) ((Math.random() * 6 ) + 1); 21 } 22 23 public Die(int nrOfSides) 24 { 25 order = nrOfSides; 26 top = (int) ((Math.random() * nrOfSides) + 1); 27 } 28 29 // THE METHODS (BEHAVIOR) 30 31 public int top() 32 { 33 return top; 34 } 35 36 public void roll() 37 { 38 top = (int) ((Math.random() * order) + 1); 39 } 40 } 41