1 /* 2 * Model a die in term 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 (state) 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 public Die (int nrofsides){ 20 order = nrofsides; 21 top = (int) ((Math.random()*nrofsides)+1); 22 } 23 // The methods (behavior) 24 public int top(){ 25 return top; 26 } 27 public void roll(){ 28 top=(int) ((Math.random()*order)+1); 29 } 30 } 31