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