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