Die.java
1    
2    // model die in terms of two properties
3    //order, number of faces
4    // top the value of the top face
5    package chance;
6    
7    public class Die {
8        //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