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   
11       public static void main(String[] args) {
12   
13           //create a standard die and roll it 5 times
14           createAndRollStandardDieFiveTimes();
15   
16           //create a twenty sided die and roll it 5 times
17           createAndRollTwentySidedDieFiveTimes();
18   
19           //create a standard die and roll it 20 times
20           createAndRollStandardDie(20);
21   
22           //create a standard die and roll it 30 times
23           createAndRollStandardDie(30);
24   
25           //create a nine sided side and roll it 20 times
26           createAndRollNineSidedDie(20);
27   
28           //create a nine sided side and roll it 30 times
29           createAndRollNineSidedDie(30);
30   
31           //ten times create a standard die and roll it until you get a 1
32           System.out.println("Ten times, roll a standard die for a 1");
33           for (int i = 1; i <= 10; i++) {
34               createAndRollStandardDieFor1();
35           }
36   
37           //ten times create a twelve sided die and roll it until you get a 1
38           System.out.println("Ten times, roll a twelve sided die for a 1");
39           for (int i = 1; i <= 10; i++) {
40               createAndRollTwelveSidedDieFor1();
41           }
42           //showcase the toString method of both the standard die and other faceted dice
43           stringRepresentation();
44       }
45   
46       private static void createAndRollStandardDieFiveTimes() {
47           System.out.println("Roll a standard die 5 times ...");
48           Die die = new Die();
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 createAndRollTwentySidedDieFiveTimes() {
58           System.out.println("Roll a standard die 5 times ...");
59           Die die = new Die(20);
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           System.out.println();
66       }
67   
68       private static void createAndRollStandardDie(int nrOfTimes) {
69           System.out.println("Roll a standard die "+ nrOfTimes + " times ..." );
70           Die lucky = new Die();
71   //        //using a for loop
72   //        for(int i = 1; i <= nrOfTimes; i = i+1) {
73   //            lucky.roll();
74   //            System.out.print(lucky.top() + " ");
75   //        }
76   //        System.out.println();
77   
78           //using a while loop
79           int i = 1;
80           while (i <= nrOfTimes) {
81               lucky.roll();
82               System.out.print(lucky.top() + " ");
83               i = i+1;
84           }
85           System.out.println();
86       }
87   
88       private static void createAndRollNineSidedDie(int nrOfTimes) {
89           System.out.println("Roll a nine sided die "+ nrOfTimes + " times ..." );
90           Die nineSider = new Die(9);
91           for(int i = 1; i <= nrOfTimes; i = i+1) {
92               nineSider.roll();
93               System.out.print(nineSider.top() + " ");
94           }
95           System.out.println();
96   
97       }
98   
99       private static void createAndRollStandardDieFor1() {
100          Die forOne = new Die();
101          forOne.roll(); System.out.print(forOne.top()+ " ");
102          while(! (forOne.top() == 1)) {
103              forOne.roll(); System.out.print(forOne.top()+ " ");
104          }
105          System.out.println();
106  
107      }
108      private static void createAndRollTwelveSidedDieFor1() {
109          Die forTwenty = new Die(20);
110          forTwenty.roll(); System.out.print(forTwenty.top()+ " ");
111          while(! (forTwenty.top() == 1)) {
112              forTwenty.roll(); System.out.print(forTwenty.top()+ " ");
113          }
114          System.out.println();
115      }
116  
117      private static void stringRepresentation() {
118          System.out.println("Roll a standard die and a twenty side, then display in text format...");
119          Die deb = new Die();
120          System.out.println(deb);
121  
122          Die dob = new Die(20);
123          System.out.println(dob);
124      }
125  }