-
Notifications
You must be signed in to change notification settings - Fork 44
Expand file tree
/
Copy pathDice.java
More file actions
57 lines (45 loc) · 1.45 KB
/
Dice.java
File metadata and controls
57 lines (45 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import java.util.ArrayList;
import java.util.List;
public class Dice {
private ArrayList<Integer> rollingResults;
private Integer numOfDice = 2;
private Integer sumOfDice;
public Dice (Integer countOfDice) {
this.rollingResults = new ArrayList<>();
for (int i = 0; i < countOfDice; i++) {
this.rollingResults.add((int) ((Math.random() * (7 - 1)) + 1));
}
}
public ArrayList<Integer> getRollingResults() {
return rollingResults;
}
public void setRollingResults(ArrayList<Integer> rollingResults) {
this.rollingResults = rollingResults;
}
public Integer tossAndSum () {
Integer sum = 0;
for (int i = 0; i < rollingResults.size(); i++) {
rollingResults.set(i, (int) ((Math.random() * (7 - 1)) + 1));
sum += rollingResults.get(i);
}
return sum;
}
// public void initializeDiceList () {
// Integer numOfDice = getNumOfDice();
// List<Integer> rollingResults = this.getRollingResults();
// for (int i = 0; i < numOfDice; i++) {
// rollingResults.add(0);
// }
public Integer getNumOfDice() {
return numOfDice;
}
public void setNumOfDice(Integer numOfDice) {
this.numOfDice = numOfDice;
}
public Integer getSumOfDice() {
return sumOfDice;
}
public void setSumOfDice(Integer sumOfDice) {
this.sumOfDice = sumOfDice;
}
}