|
@@ -1,4 +1,45 @@
|
|
1
|
+
|
|
2
|
+import java.util.Random;
|
|
3
|
+
|
1
|
4
|
public class Dice {
|
|
5
|
+//declare variables
|
|
6
|
+ public int diceCount;
|
|
7
|
+ public int tossMax;
|
|
8
|
+ public int tossMin;
|
|
9
|
+//declare number of dice
|
|
10
|
+ public Dice() {
|
|
11
|
+ this(1);
|
|
12
|
+ }
|
|
13
|
+//get number of dice used
|
|
14
|
+ public Dice(int numOfDice) {
|
|
15
|
+ this.diceCount = numOfDice;
|
|
16
|
+ this.tossMax = this.diceCount * 6;
|
|
17
|
+ this.tossMin = this.diceCount;
|
|
18
|
+ }
|
|
19
|
+//getters for maximum and minimum number of tosses
|
|
20
|
+ public int getTossMax() {
|
|
21
|
+ return tossMax;
|
|
22
|
+ }
|
|
23
|
+
|
|
24
|
+ public int getTossMin() {
|
|
25
|
+ return tossMin;
|
|
26
|
+ }
|
2
|
27
|
|
|
28
|
+ public int sumOfToss() {
|
|
29
|
+ int sum = 0;
|
|
30
|
+ for (int i = 0; i < diceCount; i++) {
|
|
31
|
+ sum += (int)(Math.random() * 6) + 1;
|
|
32
|
+ }
|
|
33
|
+ return sum;
|
|
34
|
+ }
|
3
|
35
|
|
4
|
|
-}
|
|
36
|
+ public static void main(String[] args) {
|
|
37
|
+//instance of number of dice used for each game
|
|
38
|
+ Dice game1 = new Dice(2);
|
|
39
|
+ Dice game2 = new Dice(5);
|
|
40
|
+ Integer tossForGame1 = game1.sumOfToss();
|
|
41
|
+ Integer tossForGame2 = game2.sumOfToss();
|
|
42
|
+ System.out.println(tossForGame1);
|
|
43
|
+ System.out.println(tossForGame2);
|
|
44
|
+ }
|
|
45
|
+}
|