Roller.java
1    /* 
2     * Program to make use of the Die class. 
3     */
4    package chanceapps;
5    
6    import chance.Die;
7    
8    public class Roller {
9    
10       public static void main(String[] args) {
11           // CREATE A STANDARD DIE AND ROLL IT 5 TIMES
12           createAndRollStandardDieFiveTimes();
13           // CREATE A TWENTY SIDED DIE AND ROLL IT 5 TIMES
14           createAndRollTwentySidedDieFiveTimes();
15           // CREATE A STANDARD DIE AND ROLL IT 20 TIMES
16           createAndRollStandardDie(20);
17           // CREATE A STANDARD DIE AND ROLL IT 30 TIMES
18           createAndRollStandardDie(30);
19           // CREATE A NINE SIDED DIE AND ROLL IT 20 TIMES
20           createAndRollNineSidedDie(20);
21           // CREATE A NINE SIDED DIE AND ROLL IT 30 TIMES
22           createAndRollNineSidedDie(30);
23           // TEN TIMES, CREATE A STANDARD DIE AND ROLL IT UNTIL YOU GET A 1
24           System.out.println("Ten times, roll a standard die for a 1.");
25           for (int i = 1; i <= 10; i++) {
26               createAndRollStandardDieFor1();
27           }
28           // TEN TIMES, CREATE A TWELVE SIDED DIE AND ROLL IT UNTIL YOU GET A 1
29           System.out.println("Ten times, roll a twelve sided die for a 1.");
30           for (int i = 1; i <= 10; i++) {
31               createAndRollTwelveSidedDieFor1();
32           }
33       }
34   
35       private static void createAndRollStandardDieFiveTimes() {
36           System.out.println("Roll a standard die 5 times ...");
37           Die die = new Die();
38           die.roll(); System.out.print(die.top() + " ");
39           die.roll(); System.out.print(die.top() + " ");
40           die.roll(); System.out.print(die.top() + " ");
41           die.roll(); System.out.print(die.top() + " ");
42           die.roll(); System.out.print(die.top() + " ");
43           System.out.println();
44       }
45   
46       private static void createAndRollTwentySidedDieFiveTimes() {
47           System.out.println("Roll a nonstandard twenty sided die 5 times ...");
48           Die die = new Die(20);
49           die.roll(); System.out.print(die.top() + " ");
50           die.roll(); System.out.print(die.top() + " ");
51           die.roll(); System.out.print(die.top() + " ");
52           die.roll(); System.out.print(die.top() + " ");
53           die.roll(); System.out.print(die.top() + " ");
54           System.out.println();
55       }
56   
57       private static void createAndRollStandardDie(int nrOfTimes) {
58           System.out.println("Roll a standard die " + nrOfTimes + " times ...");
59           Die lucky = new Die();
60           //for (int i = 1; i <= nrOfTimes; i = i + 1) {
61               //lucky.roll();
62               //System.out.print(lucky.top() + " ");
63          // }
64           //System.out.println();
65           int i = 1;
66           while (i <= nrOfTimes) {
67               lucky.roll();
68               System.out.print(lucky.top() + " ");
69               i = i + 1;
70           }
71           System.out.println();
72       }
73   
74       private static void createAndRollNineSidedDie(int nrOfTimes) {
75           System.out.println("Roll a nine sided die " + nrOfTimes + " times ...");
76           Die lucky2 = new Die(9);
77           int i = 1;
78           while (i <= nrOfTimes) {
79               lucky2.roll();
80               System.out.print(lucky2.top() + " ");
81               i = i + 1;
82           }
83           System.out.println();
84       }
85   
86       private static void createAndRollStandardDieFor1() {
87           Die lucky3 = new Die();
88           lucky3.roll(); System.out.print(lucky3.top() + " ");
89           while (lucky3.top()!= 1) {
90               lucky3.roll();
91               System.out.print(lucky3.top() + " ");
92           }
93           System.out.println();
94       }
95   
96       private static void createAndRollTwelveSidedDieFor1() {
97           Die lucky4 = new Die(12);
98           lucky4.roll(); System.out.print(lucky4.top() + " ");
99           while (lucky4.top()!= 1) {
100              lucky4.roll();
101              System.out.print(lucky4.top() + " ");
102          }
103          System.out.println();
104      }
105  
106  }