1 package chance; 2 3 public class Die { 4 // The instance variables (state) 5 private int order; 6 private int top; 7 8 // the constructors 9 10 public Die(){ 11 order=6; 12 top = (int)((Math.random()*6)+1); 13 14 } 15 public Die(int nrOfSides) { 16 order = nrOfSides; 17 top = (int)((Math.random()*nrOfSides)+1); 18 19 } 20 21 // the methods (behavior) 22 23 public int top() { 24 return top; 25 26 } 27 28 public void roll() { 29 top = (int)((Math.random()*order)+1); 30 31 } 32 } 33