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 8 package chance; 9 10 public class Die { 11 12 // The instance variables ( state ) 13 14 private int order; 15 private int top; 16 17 // The constructors 18 19 public Die() { 20 order = 6; 21 top = (int) ( (Math.random() * 6 ) + 1 ); 22 } 23 24 public Die(int nrOfSides) { 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 42 43 44