1 2 /* 3 * model a die in terms of two properties: 4 * - order, the number of faces 5 * - top, the value of the top face 6 */ 7 8 package chance; 9 10 public class Die { 11 12 private int order; 13 private int top; 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 25 public int top() { 26 return top; 27 } 28 29 public void roll() { 30 top = (int) ((Math.random() * order) + 1); 31 } 32 } 33