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