1 //model the die in terms of 2 //order= # of faces 3 //top= value on top face 4 package chance; 5 6 public class Die { 7 //instance variables 8 private int order; 9 private int top; 10 11 //constructors 12 public Die(){ 13 order=6; 14 top = (int)((Math.random()* 6)+ 1); 15 } 16 public Die(int nrOfSides){ 17 order = nrOfSides; 18 top= (int)((Math.random()*nrOfSides)+1); 19 } 20 21 //methods (behavior) 22 public int top(){ 23 return top; 24 } 25 public void roll(){ 26 top=(int)((Math.random()*order)+1); 27 } 28 } 29