forked from team294/Java_Challenge_2023
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQuestion2.java
More file actions
49 lines (38 loc) · 1.11 KB
/
Question2.java
File metadata and controls
49 lines (38 loc) · 1.11 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
public class Question2 {
public static void main(String[] args) {
int rolls[] = {0, 0, 0, 0, 0, 0};
Die die = new Die();
for (int i = 0; i < 1000; i++) {
rolls[die.roll() - 1]++;
}
for (int i = 0; i < 6; i++) {
System.out.println(Integer.toString(i + 1) + " was rolled " + Integer.toString(rolls[i]) + " times.");
}
Die specialDie = new Die(1000);
if (specialDie.roll() == 1) {
System.out.println("You are special :D");
} else {
System.out.println("You are not special D:");
}
}
static class Die {
int sides = 0;
int lastRoll = -1;
public Die() {
this.sides = 6;
}
public Die(int _sides) {
this.sides = _sides;
}
public int numSides() {
return this.sides;
}
public int roll() {
lastRoll = (int) Math.floor(Math.random() * sides) + 1;
return lastRoll;
}
public int readLastRoll() {
return lastRoll;
}
}
}