Die.java
1    // model die in terms of two properties
2    //order, number of faces
3    // top the value of the top face
4    
5    package chance;
6    
7    public class Die {
8    
9        //instance variables (state)
10   
11       private int order;
12       private int top;
13   
14       // the constructors
15   
16       public Die() {
17           order = 6;
18           top = (int) ( ( Math.random() * 6 ) + 1);
19       }
20   
21       public  Die(int nrOfSides) {
22           order = nrOfSides;
23           top = (int) ((Math.random() * nrOfSides) + 1);
24       }
25   
26       // the methods behavior
27   
28       public int top() {
29           return top;
30       }
31   
32       public void roll() {
33           top = (int) ((Math.random() * order ) + 1);
34       }
35   }
36