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 package chance; 7 8 public class Die { 9 10 // THE INSTANCE VARIABLES (STATE) 11 12 private int order; 13 private int top; 14 15 // THE CONSTRUCTORS 16 17 public Die() { 18 order = 6; 19 // the math random times sth will return a double than it is added 1 so 20 // when (int), it will chop down the decimals 21 top = (int) ((Math.random()*6)+1); 22 } 23 public Die(int nrOfSides){ 24 order = nrOfSides; 25 top = (int) ((Math.random()*nrOfSides)+1); 26 } 27 28 // THE METHODS (BEHAVIOR) 29 30 public int top() { 31 return top; 32 } 33 34 public void roll() { 35 top = (int) ((Math.random()* order)+1); 36 } 37 } 38