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