1 package chance; 2 3 public class Die { 4 5 //The instance variables (State) 6 7 private int order; 8 private int top; 9 10 //The constructors 11 12 public Die(){ 13 order = 6; 14 top = (int) ((Math.random() * 6) + 1); //Convert to int so it never equals anything greater than 6 15 } 16 public Die(int nrOfSides){ 17 order = nrOfSides; 18 top = (int) ((Math.random() * nrOfSides) + 1); 19 } 20 21 //The methods (Behavior) 22 23 public int top() { 24 return top; 25 } 26 27 public void roll(){ 28 top = (int) ((Math.random() * order) + 1); 29 } 30 } 31