Die.java
1    package chance;
2    /* 
3     * Model a die in terms of two properties: 
4     * - order, the number of faces 
5     * - top, the value of the top face 
6     */
7    public class Die {
8        //THE INSTANCE VARIABLES (STATE)
9    
10       private int order;
11       private int top;
12   
13       //THE CONSTRUCTORS
14   
15       public Die(){
16           order = 6;
17           top = (int)((Math.random() * 6) + 1);
18       }
19   
20       public Die(int nrOfSides){
21           order = nrOfSides;
22           top = (int)((Math.random() * nrOfSides) + 1);
23       }
24   
25       //THE METHODS (BEHAVIOR)
26   
27       public int top(){
28           return top;
29       }
30   
31       public void roll(){
32           top = (int)((Math.random() * order) + 1);
33       }
34   }
35