Die.java
1    package chance;
2    
3    public class Die {
4    
5        //THE INSTANCE VARIABLES (STATE)
6    
7        private int order;
8        private int top;
9    
10       //THE CONSTRUCTORS
11   
12       public Die () {
13           order = 6;
14           top = (int) ((Math.random() * 6) + 1);
15       }
16       public Die(int nrOfSides) {
17           order = nrOfSides;
18           top = (int) ((Math.random() * order) + 1);
19       }
20   
21       //The Methods (Behavior)
22   
23       public int top(){
24           return top;
25       }
26   
27       public void roll() {
28           top = (int)((Math.random() * order) + 1);
29       }
30   }
31