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 package chance; 8 9 public class Die { 10 // the instance variables 11 private int order; 12 private int top; 13 14 // the constructors 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 // the methods (behavior) 26 public int top() { 27 return top; 28 } 29 30 public void roll() { 31 top = (int)((Math.random()*order)+1); 32 } 33 }