1 package chanceapps; 2 3 import chance.Die; 4 5 public class Roller { 6 7 public static void main(String[] args) { 8 //CREATE A STANDARD DIE AND ROLL IT 5 TIMES 9 createAndRollStandardDieFiveTimes(); 10 //CREATE A TWENTY SIDED DIE AND ROLL IT 5 TIMES 11 createAndRollTwentySidedDieFiveTimes(); 12 //CREATE A STANDARD DIE AND ROLL IT 20 TIMES 13 createAndRollStandardDie(20); 14 //CREATE A STANDARD DIE AND ROLL IT 30 TIMES 15 createAndRollStandardDie(30); 16 //CREATE A NINE SIDED DIE AND ROLL IT 20 TIMES 17 createAndRollNineSidedDie(20); 18 //CREATE A NINE SIDED DIE AND ROLL IT 30 TIMES 19 createAndRollNineSidedDie(30); 20 //TEN TIMES, CREATE A STANDARD DIE AND ROLL IT UNTIL YOU GET A 1 21 for (int i = 1; i <= 10; i++) { 22 createAndRollStandardDieFor1(); 23 } 24 //TEN TIMES, CREATE A TWELVE SIDED DIE AND ROLL IT UNTIL YOU GET A 1 25 System.out.println("Ten times, roll a twelve sided die for a 1."); 26 for ( int i = 1; i <= 10; i++){ 27 createAndRollTwelveSidedDieFor1(); 28 } 29 } 30 31 private static void createAndRollStandardDieFiveTimes() { 32 System.out.println("Roll a standard die 5 times ..."); 33 Die die = new Die(); 34 die.roll(); System.out.print(die.top() + " "); 35 die.roll(); System.out.print(die.top() + " "); 36 die.roll(); System.out.print(die.top() + " "); 37 die.roll(); System.out.print(die.top() + " "); 38 die.roll(); System.out.print(die.top() + " "); 39 System.out.println(); 40 } 41 42 private static void createAndRollTwentySidedDieFiveTimes() { 43 Die twentySidedDie = new Die(20); 44 twentySidedDie.roll(); System.out.print(twentySidedDie.top() + " "); 45 twentySidedDie.roll(); System.out.print(twentySidedDie.top() + " "); 46 twentySidedDie.roll(); System.out.print(twentySidedDie.top() + " "); 47 twentySidedDie.roll(); System.out.print(twentySidedDie.top() + " "); 48 twentySidedDie.roll(); System.out.print(twentySidedDie.top() + " "); 49 System.out.println(); 50 } 51 private static void createAndRollStandardDie(int nrOfTimes) { 52 System.out.println("Roll a standard die " + nrOfTimes + "times ..."); 53 Die lucky = new Die(); 54 int i = 1; 55 while (i <= nrOfTimes) { 56 lucky.roll(); 57 System.out.print(lucky.top() + " "); 58 i = i + 1; 59 } 60 System.out.println(); 61 } 62 private static void createAndRollNineSidedDie(int nrOfTimes) { 63 System.out.println("Roll a nine sided die " + nrOfTimes + "times ..."); 64 Die nines = new Die(9); 65 for (int i = 1; i <= nrOfTimes; i = i + 1) { 66 nines.roll(); 67 System.out.print(nines.top() + " "); 68 } 69 System.out.println(); 70 } 71 private static void createAndRollStandardDieFor1() { 72 Die standard1 = new Die(); 73 int i = standard1.top(); 74 System.out.println("Roll a standard die for a 1 ..."); 75 if (i ==1 ) { 76 System.out.print(i); 77 } 78 while (i != 1) { 79 standard1.roll(); 80 System.out.print(standard1.top() + " "); 81 i = standard1.top(); 82 } 83 System.out.println(); 84 } 85 private static void createAndRollTwelveSidedDieFor1() { 86 Die twelveFor1 = new Die(); 87 int i = twelveFor1.top(); 88 System.out.println("Roll a twelve sided die for a 1 ..."); 89 if (i ==1 ) { 90 System.out.print(i); 91 } 92 while (i != 1) { 93 twelveFor1.roll(); 94 System.out.print(twelveFor1.top() + " "); 95 i = twelveFor1.top(); 96 } 97 System.out.println(); 98 } 99 } 100