1 2 3 4 5 package chance; 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 //CREATE A TWENTY SIDED DIE AND ROLL IT 5 TIMES 14 createAndRollTwentySidedDieFiveTimes(); 15 //CREATE A STANDARD DIE AND ROLL IT 20 TIMES 16 createAndRollStandardDie(20); 17 //CREATE A STANDARD DIE AND ROLL IT 30 TIMES 18 createAndRollStandardDie(30); 19 //CREATE A NINE SIDED DIE AND ROLL IT 20 TIMES 20 createAndRollNineSidedDie(20); 21 //CREATE A NINE SIDED DIE AND ROLL IT 3O TIMES 22 createAndRollNineSidedDie(30); 23 //TEN TIMES, CREATE A STANDARD DIE AND ROLL IT UNTIL YOU GET A 1 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 //TEN TIMES, CREATE A TWELVE SIDED DIE AND ROLL IT UNTIL YOU GET A 1 29 System.out.println("Ten times, roll a twelve sided die for a 1."); 30 for(int i = 1; i <= 10; i++){ 31 createAndRollTwelveSidedDieFor1(); 32 } 33 } 34 35 private static void createAndRollStandardDieFiveTimes(){ 36 System.out.println("Roll a standard die 5 times... "); 37 Die die = new Die(); 38 die.roll(); System.out.println(die.top() + " "); 39 die.roll(); System.out.println(die.top() + " "); 40 die.roll(); System.out.println(die.top() + " "); 41 die.roll(); System.out.println(die.top() + " "); 42 die.roll(); System.out.println(die.top() + " "); 43 System.out.println(); 44 } 45 46 private static void createAndRollTwentySidedDieFiveTimes(){ 47 // throw new UnsupportedOperationException("Not supported yet. "); 48 System.out.println("Roll a twenty sided die 5 times... "); 49 Die die = new Die(20); 50 die.roll(); System.out.println(die.top() + " "); 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 System.out.println(); 56 } 57 58 private static void createAndRollStandardDie(int nrOfTimes){ 59 //throw new UnsupportedOperationException("Not supported yet. "); 60 System.out.println("Roll a standard die " + nrOfTimes + " times... "); 61 Die lucky = new Die(); 62 int i = 1; 63 while ( i <= nrOfTimes ){ 64 lucky.roll(); 65 System.out.println(lucky.top() + " "); 66 i = i + 1; 67 } 68 System.out.println(); 69 } 70 71 private static void createAndRollNineSidedDie(int nrOfTimes){ 72 //throw new UnsupportedOperationException("Not supported yet. "); 73 System.out.println("Roll a nine sided die " + nrOfTimes + " times... "); 74 Die lucky = new Die(9); 75 int i = 1; 76 while ( i <= nrOfTimes ){ 77 lucky.roll(); 78 System.out.println(lucky.top() + " "); 79 i = i + 1; 80 } 81 System.out.println(); 82 } 83 84 private static void createAndRollStandardDieFor1(){ 85 //throw new UnsupportedOperationException("Not supported yet. "); 86 Die die = new Die(); 87 die.roll(); System.out.print(die.top()); 88 while ( die.top() > 1){ 89 die.roll(); 90 System.out.print(die.top()); 91 } 92 System.out.println(); 93 } 94 95 private static void createAndRollTwelveSidedDieFor1(){ 96 //throw new UnsupportedOperationException("Not supported yet. "); 97 Die die = new Die(12); 98 die.roll(); System.out.print(die.top()); 99 while ( die.top() > 1 ){ 100 die.roll(); 101 System.out.print(die.top()); 102 } 103 System.out.println(); 104 } 105 } 106