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