Roller.java
1    /* Program to make use of the die 
2    * 
3     */
4    
5    package chanceapps;
6    import chance.Die;
7    public class Roller {
8        public static void main(String [] args){
9            // Creat a standard die and roll it 5 times
10           createAndRollStandardDieFiveTimes();
11   
12           //create a twenty dided die and roll it five times
13           createAndRollTwentySidedDieFiveTimes();
14           //create a standard die and roll it 20 times
15           createAndRollStandardDie(20);
16           //create a standard die and roll it 30 times
17           createAndRollStandardDie(30);
18           //creta a nine sided die and roll it 20 times
19           createAndRollNineSidedDie(20);
20           // create a nine sided die and roll it 30 times
21           createAndRollNineSidedDie(30);
22           //Ten times, create a Standard die and roll it until u get a 1
23   
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   
29           //Ten times, creeate a twelve sided die and roll it until you get A 1
30           System.out.println("ten times, roll a twelve sided die for a 1.");
31           for (int i=1; i<=10; i++){
32               createAndRollTwelveSidedDieFor1();
33           }
34   
35       }
36       private static void createAndRollStandardDieFiveTimes() {
37           System.out.println("Roll a standard die 5 time....");
38           Die die = new Die();
39           die.roll();
40           System.out.print(die.top() + " ");
41           die.roll();
42           System.out.print(die.top() + " ");
43           die.roll();
44           System.out.print(die.top() + " ");
45           die.roll();
46           System.out.print(die.top() + " ");
47           die.roll();
48           System.out.print(die.top() + " ");
49           System.out.println();
50       }
51       private static void createAndRollTwentySidedDieFiveTimes() {
52           System.out.println("Roll a standard twenty sided die 5 time....");
53           Die die = new Die(20);
54           die.roll();
55           System.out.print(die.top() + " ");
56           die.roll();
57           System.out.print(die.top() + " ");
58           die.roll();
59           System.out.print(die.top() + " ");
60           die.roll();
61           System.out.print(die.top() + " ");
62           die.roll();
63           System.out.print(die.top() + " ");
64           System.out.println();
65   
66       }
67       private static void  createAndRollStandardDie(int nrOfTimes){
68           System.out.println("Roll a standard die"+nrOfTimes+" time...");
69           Die lucky = new Die();
70           for (int i=1; i<=nrOfTimes;i=i+1){
71               lucky.roll();
72               System.out.print(lucky.top()+" ");
73           }
74           System.out.println();
75       }
76       private static void createAndRollNineSidedDie(int nrOftimes){
77           System.out.println("Roll a nine sided die"+nrOftimes+ "time..");
78           Die lucky= new Die(9);
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       private static void createAndRollStandardDieFor1(){
88           Die die= new Die();
89           die.roll();
90           System.out.print(die.top() + " ");
91           while (die.top()!=1){
92               die.roll();
93               System.out.print(die.top() + " ");
94           }
95           System.out.println();
96       }
97   
98       private static void createAndRollTwelveSidedDieFor1() {
99           Die die= new Die(12);
100          die.roll();
101          System.out.print(die.top()+" ");
102          while (die.top()!=1) {
103              die.roll();
104              System.out.print(die.top() + " ");
105          }
106          System.out.println();
107      }
108  }
109