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    
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       public Die(int nrOfSides) {order = nrOfSides;top = (int) ( ( Math.random() * nrOfSides ) + 1);}
19       // THE METHODS (BEHAVIOR)
20       public int top() {
21           return top;
22       }public void roll() {
23           top = (int) ( ( Math.random() * order ) + 1);
24       }
25   
26   }
27   
28