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