/home/mbilodea/NetBeansProjects/CS1/src/chance/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 /**
 9  *
10  * @author mbilodea
11  */
12 public class Die {
13     
14     // THE INSTANCE VARIABLES (STATE)
15     
16     private int order;
17     private int top;
18     
19     // THE CONSTRUCTORS
20     
21     public Die() {
22         order = 6;
23         top = (int) ( (Math.random() * 6 ) + 1);
24     }
25     
26     public Die(int nrOfSides) {
27         order = nrOfSides;
28         top = (int) ( ( Math.random() * nrOfSides ) + 1);
29     }
30     
31     // THE METHODS (BEHAVIOR)
32     
33     public int top() {
34         return top;
35     }
36     
37     public void roll() {
38         top = (int) ( ( Math.random() * order ) + 1);
39     }
40 }
41