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   
14           //Create a twenty sided die and roll it 5 times
15   
16           createAndRollTwentySidedDieFiveTimes();
17   
18           //Create and roll a standard die 20 times
19   
20           createAndRollStandardDie(20);
21   
22           //Create and roll a standard die 30 times
23   
24           createAndRollStandardDie(30);
25   
26           //Create a nine sided die and roll it 20 times
27   
28           createAndRollNineSidedDie(20);
29   
30           //Create and roll a 9 sided die 30 times
31           System.out.println("Thirty times, roll a 9 sided die for a 1.");
32           createAndRollNineSidedDie(30);
33   
34   
35           //Ten Times, create a standard die and roll it until you get a 1
36           System.out.println("Ten times, roll a standard die for a 1.");
37           for (int i =1; i<= 10; i++){
38               createAndRollStandardDieFor1();
39           }
40   
41           //Ten times, Create a twelve sided die and roll it until  you get a 1
42           //System.out.println("Ten times, roll a twelve sided die for a 1.")
43           for(int i = 1; i <=10; i++){
44               createAndRollTwelveSidedDieFor1();
45           }
46       }
47   
48       private static void createAndRollStandardDieFiveTimes(){
49           System.out.println("Roll a standard die 5 times...");
50           Die die = new Die();
51           die.roll(); System.out.println(die.top() + " ");
52           die.roll(); System.out.println(die.top() + " ");
53           die.roll(); System.out.println(die.top() + " ");
54           die.roll(); System.out.println(die.top() + " ");
55           die.roll(); System.out.println(die.top() + " ");
56           System.out.println();
57         /*  for(int i = 1; i <=10; i++) { 
58               //This creates an infinte loop of calling same method don't do this: createAndRollStandardDieFiveTimes(); 
59               Die die = new Die(); 
60               die.roll(); System.out.println(die.top() +  " "); 
61    
62           }*/
63       }
64       private static void createAndRollTwentySidedDieFiveTimes(){
65           //Filler code when code isn't done?
66           //throw new UnsupportedOperationException("Not supported yet");
67           System.out.println(("Roll a Twenty sided die 5 times "));
68           Die Twenty = new Die(20);
69           Twenty.roll(); System.out.println(Twenty.top()+ " ");
70           Twenty.roll(); System.out.println(Twenty.top()+ " ");
71           Twenty.roll(); System.out.println(Twenty.top()+ " ");
72           Twenty.roll(); System.out.println(Twenty.top()+ " ");
73           Twenty.roll(); System.out.println(Twenty.top()+ " ");
74           Twenty.roll(); System.out.println(Twenty.top()+ " ");
75       }
76   
77       private static void createAndRollStandardDie(int nrOfTimes){
78           //throw new UnsupportedOperationException("Not supported yet");
79           System.out.println("Roll a standard die " +nrOfTimes+ " times...");
80           Die lucky = new Die();
81           /*for (int i = 1; i<= nrOfTimes; i =i + 1){ 
82               lucky.roll(); 
83               System.out.print(lucky.top() + " "); 
84           }*/
85           int i = 1;
86           while(i <= nrOfTimes){
87               i = i +1;
88               lucky.roll();
89               System.out.println(lucky.top() + " ");
90           }
91           System.out.println();
92   
93       }
94   
95       private static void createAndRollNineSidedDie(int nrOfTimes){
96           //throw new UnsupportedOperationException("Not supported yet");\
97           System.out.println("Roll a 9 sided die " +nrOfTimes+ " times...");
98           Die ninedie = new Die();
99           int i = 1;
100          while(i <= nrOfTimes){
101              i = i +1;
102              ninedie.roll();
103              System.out.println(ninedie.top() + " ");
104          }
105          System.out.println();
106  
107  
108      }
109  
110      private static void createAndRollStandardDieFor1(){
111          //throw new UnsupportedOperationException("Not supported yet");
112          Die onlyOne = new Die();
113          onlyOne.roll();
114          System.out.print(onlyOne.top() + " ");
115          while (onlyOne.top()!= 1 ){
116              onlyOne.roll();
117              System.out.print(onlyOne.top() + " ");
118          }
119          System.out.println();
120  
121      }
122  
123      private static void createAndRollTwelveSidedDieFor1(){
124          //throw new UnsupportedOperationException("Not supported yet");
125          Die onlyOne2 = new Die();
126          onlyOne2.roll();
127          System.out.print(onlyOne2.top() + " ");
128          while (onlyOne2.top()!= 1 ){
129              onlyOne2.roll();
130              System.out.print(onlyOne2.top() + " ");
131          }
132          System.out.println();
133      }
134  
135  }
136