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