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