/home/rkanin/NetBeansProjects/CS1/src/chanceapps/Roller.java
  1 /*
  2  *Program to make use of the Die class
  3  */
  4 package chanceapps;
  5 
  6 import chance.Die;
  7 
  8 
  9 /**
 10  *
 11  * @author rkanin
 12  */
 13 public class Roller {
 14 
 15     /**
 16      * @param args the command line arguments
 17      */
 18     public static void main(String[] args) {
 19         // CREATE A STANDARD DIE AND ROLL IT 5 TIMES
 20         createAndRollStandardDieFiveTimes();
 21         //CREATE A TWENTY SIDED DIE AND ROLL IT 5 TIMES
 22         createAndRollTwentySidedDieFiveTimes();
 23         //CREATE A STANDARD DIE AND ROLL IT 20 TIMES
 24         createAndRollStandardDie(20);
 25         //CREATE A STANDARD DIE AND ROLL IT 30 TIMES
 26         createAndRollStandardDie(30);
 27         // CREATE A TEN SIDED DIE AND ROLL IT 20 TIMES
 28         createAndRollNineSidedDie(20);
 29         // CREATE A NINE SIDED DIE AND ROLL IT 30 TIMES
 30         createAndRollNineSidedDie(30);
 31         // TEN TIMES, CREATE A STANDARD DIE AND ROL 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         // TEN TIMES, CEATE A TWELVE SIDED DIE AND ROLL IT UNTIL YOU GET A 1
 37         System.out.println("Ten TImes, roll a twelve sided die for a 1.");
 38         for (int i = 1; i <=10; i++) {
 39             createAndRollTwelveSidedDieFor1();
 40         }
 41     }
 42 
 43     private static void createAndRollStandardDieFiveTimes() {
 44         System.out.println("Roll a standard die 5 times...");
 45         Die die = new Die();
 46         die.roll();
 47         System.out.print(die.top() + " ");
 48         die.roll();
 49         System.out.print(die.top() + " ");
 50         die.roll(); 
 51         System.out.print(die.top() + " ");
 52         die.roll();
 53         System.out.print(die.top() + " ");
 54         die.roll();
 55         System.out.print(die.top() + " ");
 56         System.out.println();
 57         
 58     }
 59 
 60     private static void createAndRollTwentySidedDieFiveTimes() {
 61         System.out.println("Roll a nonstandard twenty sided die five times...");
 62         Die die = new Die(20);
 63         die.roll();
 64         System.out.print(die.top() + " ");
 65         die.roll();
 66         System.out.print(die.top() + " ");
 67         die.roll();
 68         System.out.print(die.top() + " ");
 69         die.roll();
 70         System.out.print(die.top() + " ");
 71         die.roll();
 72         System.out.print(die.top() + " ");
 73         System.out.println();
 74         
 75         
 76     }
 77 
 78     private static void createAndRollStandardDie(int nrOfTimes) {
 79         System.out.println("Roll a standard die " + nrOfTimes + " times...");
 80         Die lucky = new Die();
 81         
 82         int i = 1;
 83         while(i <= nrOfTimes){
 84             lucky.roll();
 85             System.out.print(lucky.top() + " ");
 86              i++;
 87         }
 88         System.out.println();
 89     }
 90 
 91     private static void createAndRollNineSidedDie(int nrOfTimes) {
 92         System.out.println("Roll a standard die " + nrOfTimes + " times...");
 93         Die lucky = new Die(9);
 94         int i = 1;
 95         while(i <= nrOfTimes){
 96             lucky.roll();
 97             System.out.print(lucky.top() + " ");
 98              i++;
 99         }
100         System.out.println();
101         
102     }
103 
104     private static void createAndRollStandardDieFor1() {
105         Die lucky = new Die();
106         lucky.roll();
107         System.out.print(lucky.top() + " ");
108         
109         int i = 1;
110         while( lucky.top()!= 1){
111             lucky.roll();
112             System.out.print(lucky.top() + " ");
113             i++;
114     }
115         System.out.println();
116 
117     }
118 
119     private static void createAndRollTwelveSidedDieFor1() {
120         Die lucky = new Die(20);
121         int i = 1;
122         while ( lucky.top() != 1){
123             lucky.roll();
124             System.out.print(lucky.top() + " ");
125              i++;
126     }
127         System.out.println();
128            }
129    
130         }
131         
132