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