Roller.java
1    /* 
2     *Program to make use of the Die class 
3     */
4    
5    package chanceapps;
6    
7    import chance.Die;
8    
9    public class Roller {
10       public static void main(String[] args){
11           //Create a standard die and roll it 5 times
12           createAndRollStandardDieFiveTimes();
13           //Create a standard die and roll it 20 times
14           createAndRollTwentySideDieFiveTimes();
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 lucky = new Die();
38           lucky.roll(); System.out.print(lucky.top() + " ");
39           lucky.roll(); System.out.print(lucky.top() + " ");
40           lucky.roll(); System.out.print(lucky.top() + " ");
41           lucky.roll(); System.out.print(lucky.top() + " ");
42           lucky.roll(); System.out.print(lucky.top() + " ");
43           System.out.println();
44       }
45       private static void createAndRollTwentySideDieFiveTimes(){
46           //throw new UnsupportedOperationException("Not supported yet.");
47           System.out.println("Roll a Twenty sided Die 5 times ...");
48           Die lucky = new Die(20);
49           lucky.roll(); System.out.print(lucky.top() + " ");
50           lucky.roll(); System.out.print(lucky.top() + " ");
51           lucky.roll(); System.out.print(lucky.top() + " ");
52           lucky.roll(); System.out.print(lucky.top() + " ");
53           lucky.roll(); System.out.print(lucky.top() + " ");
54           System.out.println();
55       }
56   
57       private static void createAndRollStandardDie(int nrOfTimes) {
58           //throw new UnsupportedOperationException("Not supported yet.");
59           System.out.println("Roll a standard Die ...");
60           Die lucky = new Die();
61           for (int i = 1; i <= nrOfTimes; i++) {
62               lucky.roll();
63               System.out.print(lucky.top() + " ");
64           }
65           System.out.println();
66       }
67   
68       private static void createAndRollNineSidedDie(int nrOfTimes){
69           //throw new UnsupportedOperationException("Not supported yet.");
70           System.out.println("Roll a nine sided die ...");
71           Die lucky = new Die(9);
72           for(int x = 1; x<= nrOfTimes;x++){
73           lucky.roll(); System.out.print(lucky.top()+ " ");
74       }System.out.println();
75       }
76   
77       private static void createAndRollStandardDieFor1(){
78           //throw new UnsupportedOperationException("Not supported yet.");
79           //System.out.println("Ten times, roll a standard die for a 1.");
80           Die lucky = new Die();
81           lucky.roll();
82           while (true) {
83               if (lucky.top() == 1) {
84                   System.out.print(lucky.top() + " ");
85                   break;
86               } else {
87                   lucky.roll();
88                   System.out.print(lucky.top() + " ");
89               }
90           }
91           System.out.println();
92       }
93   
94       private static void createAndRollTwelveSidedDieFor1(){
95           //throw new UnsupportedOperationException("Not supported yet.");
96           Die lucky = new Die(12);
97           lucky.roll();
98           while (true) {
99               if (lucky.top() == 1) {
100                  System.out.print(lucky.top() + " ");
101                  break;
102              } else {
103                  lucky.roll();
104                  System.out.print(lucky.top() + " ");
105              }
106          }
107          System.out.println();
108      }
109  }
110