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