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(STATE) 11 12 private int order; 13 private int top; 14 15 // THE CONSTRUCTORS; 16 public Die(){ 17 order =6; 18 top= (int) ((Math.random()*6)+1); 19 } 20 public Die(int nrOfSides){ 21 order= nrOfSides; 22 top= (int)((Math.random()*nrOfSides)+1); 23 } 24 //THE METHODS (BEHAVIOR) 25 public int top(){ 26 return top; 27 } 28 public void roll(){ 29 top= (int) ((Math.random()*order)+1); 30 } 31 } 32