/home/jfernan6/NetBeansProjects/CSX/src/chanceapps/Roller.java
  1   /*
  2    * Using the die clas to create a Die object and using
  3    * the object's functionality
  4    */
  5    
  6    package chanceapps;
  7    import chance.Die;
  8    
  9    /**
 10     *
 11    * @author jfernan6
 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 NINE 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 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           // TEN TIMES, CREATE 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(); System.out.print(die.top() + " ");
 47           die.roll(); System.out.print(die.top() + " ");
 48           die.roll(); System.out.print(die.top() + " ");
 49           die.roll(); System.out.print(die.top() + " ");
 50           die.roll(); System.out.print(die.top() + " ");
 51           System.out.println();
 52       }
 53   
 54       private static void createAndRollTwentySidedDieFiveTimes() {
 55           System.out.println("Roll a twenty sided die 5 times ...");
 56           Die die = new Die(20);
 57           die.roll(); System.out.print(die.top() + " ");
 58           die.roll(); System.out.print(die.top() + " ");
 59           die.roll(); System.out.print(die.top() + " ");
 60           die.roll(); System.out.print(die.top() + " ");
 61           die.roll(); System.out.print(die.top() + " ");
 62           System.out.println();
 63       }
 64   
 65       private static void createAndRollStandardDie(int nrOfTimes) {
 66           System.out.println("Roll a standard die " + nrOfTimes + " times ...");
 67           Die lucky = new Die();
 68           int i = 1;
 69           while ( i <= nrOfTimes ) {
 70           lucky.roll();
 71           System.out.print(lucky.top() + " ");
 72           i++;
 73     }
 74           System.out.println();
 75     }
 76   
 77       private static void createAndRollNineSidedDie(int nrOfTimes) {
 78           System.out.println("Roll a nine sided die " + nrOfTimes + " times ...");
 79           Die lucky = new Die(9);
 80           int i = 1;
 81           while ( i <= nrOfTimes ) {
 82               lucky.roll();
 83               System.out.print(lucky.top() + " ");
 84               i++;
 85     }
 86           System.out.println();
 87     }
 88   
 89       private static void createAndRollStandardDieFor1() {
 90           // CREATE DIE
 91           Die standard = new Die();
 92           // ROLL DIE
 93           standard.roll();
 94           // PRINT TOP FACE OF DIE
 95           System.out.print(standard.top() + " ");
 96           // PRINT TOP FACE OF DIE UNTIL YOU GET A 1
 97          while ( standard.top() != 1 ) {
 98              standard.roll();
 99              System.out.print(standard.top() + " ");
100      }
101          System.out.println();
102      }
103  
104      private static void createAndRollTwelveSidedDieFor1() {
105          Die twelveSided = new Die(12);
106          while ( twelveSided.top() != 1 ) {
107              twelveSided.roll();
108              System.out.print(twelveSided.top() + " ");
109          }
110          System.out.println();
111      }
112      
113  }
114