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    
7    package chance;
8    
9    
10   public class Die {
11   
12   
13   
14   
15   
16       // THE INSTANCE VARIABLES (STATE)
17   
18       private int order;
19       private int top;
20   
21       // THE CONSTRUCTORS
22   
23       public Die() {
24           order = 6;
25           top = (int) ((Math.random() * 6) + 1);
26       }
27   
28       public Die( int nrOfSides){
29           order = nrOfSides;
30           top = (int) ((Math.random() * nrOfSides) + 1);
31   
32       }
33   
34       // THE METHODS (BEHAVIOR)
35   
36       public int top () {
37           return top;
38   
39       }
40   
41       public void roll () {
42           top = (int) ((Math.random() * order) + 1);
43       }
44   
45   
46   
47   }
48   
49   
50   
51   
52   
53   
54   
55