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