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){
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