1 package chanceapps; 2 3 import chance.Die; 4 5 public class Roller { 6 7 public static void main(String[] args) { 8 //POINT A: creating a standard die to roll five times 9 createAndRollStandardDieFiveTimes(); 10 11 //POINT B: creating a twenty sided die to roll five times 12 createAndRollTwentySidedDieFiveTimes(); 13 14 //POINT C: creating a standard die to roll twenty times 15 createAndRollStandardDie(20); 16 17 //POINT D: creating a standard die to roll thirty times 18 createAndRollStandardDie(30); 19 20 //POINT E: creating a nine sided die to roll twenty times 21 createAndRollNineSidedDie(20); 22 23 //POINT F: creating a nine sided die to roll thirty times 24 createAndRollNineSidedDie(30); 25 26 //POINT G: creating a standard die that will roll until it gets a value of 1 27 System.out.println("Ten times, roll a standard die for a 1: "); 28 for (int i = 1; i <= 10; i++) { 29 createAndRollStandardDieFor1(); 30 } 31 32 //POINT H: creating a twelve sided die that will roll until it gets a value of 1 33 System.out.println("Ten times, roll a twelve sided die for a 1: "); 34 for (int i = 1; i <= 10; i++) { 35 createAndRollTwelveSidedDieFor1(); 36 } 37 } 38 39 //Covers POINT A 40 private static void createAndRollStandardDieFiveTimes() { 41 System.out.println("Roll a Standard Die 5 Times... "); 42 Die die = new Die(); 43 die.roll(); System.out.print(die.top() + " "); 44 die.roll(); System.out.print(die.top() + " "); 45 die.roll(); System.out.print(die.top() + " "); 46 die.roll(); System.out.print(die.top() + " "); 47 die.roll(); System.out.print(die.top() + " "); 48 System.out.println(); 49 } 50 51 //Covers POINT B 52 private static void createAndRollTwentySidedDieFiveTimes() { 53 //throw new UnsupportedOperationException("Not supported yet."); 54 System.out.println("Roll a Twelve Sided Die 5 Times"); 55 Die die12 = new Die(12); 56 die12.roll(); System.out.print(die12.top() + " "); 57 die12.roll(); System.out.print(die12.top() + " "); 58 die12.roll(); System.out.print(die12.top() + " "); 59 die12.roll(); System.out.print(die12.top() + " "); 60 die12.roll(); System.out.print(die12.top() + " "); 61 System.out.println(); 62 } 63 64 //Covers POINT C and D 65 private static void createAndRollStandardDie(int nrOfTimes) { 66 //throw new UnsupportedOperationException("Not supported yet."); 67 System.out.println("Roll a Standard Die " + nrOfTimes + " times ..."); 68 Die lucky = new Die(); 69 70 // for STATEMENT 71 //for (int i = 1; i <= nrOfTimes; i++) { 72 // lucky.roll(); 73 // System.out.print(lucky.top() + " "); 74 75 // while STATEMENT translation 76 int i = 1; 77 while (i <= nrOfTimes) { 78 lucky.roll(); 79 System.out.print(lucky.top() + " "); 80 i++; 81 } 82 83 System.out.println(); 84 } 85 86 //Covers POINT E and F 87 private static void createAndRollNineSidedDie(int nrOfTimes) { 88 //throw new UnsupportedOperationException("Not supported yet."); 89 System.out.println("Roll a Nine Sided Die " + nrOfTimes + " times ..."); 90 Die lucky9 = new Die(9); 91 int i = 1; 92 while (i <= nrOfTimes) { 93 lucky9.roll(); 94 System.out.print(lucky9.top() + " "); 95 i++; 96 } 97 98 System.out.println(); 99 } 100 101 //Covers POINT G 102 private static void createAndRollStandardDieFor1() { 103 //throw new UnsupportedOperationException("Not supported yet."); 104 Die standard = new Die(); 105 standard.roll(); 106 System.out.print(standard.top() + " "); 107 int i = 1; 108 while (standard.top() != i) { 109 standard.roll(); 110 System.out.print(standard.top() + " "); 111 } 112 System.out.println(); 113 114 115 } 116 117 //Covers POINT H 118 private static void createAndRollTwelveSidedDieFor1() { 119 //throw new UnsupportedOperationException("Not supported yet."); 120 Die twelve = new Die(12); 121 twelve.roll(); 122 System.out.print(twelve.top() + " "); 123 int i = 1; 124 while (twelve.top() != i) { 125 twelve.roll(); 126 System.out.print(twelve.top() + " "); 127 } 128 System.out.println(); 129 } 130 131 } 132