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