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