forked from team294/Java_Challenge_2023
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDie.java
More file actions
28 lines (26 loc) · 767 Bytes
/
Copy pathDie.java
File metadata and controls
28 lines (26 loc) · 767 Bytes
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
public class Die {
private int sides;
//sets initial value to -1 in case readLastRoll is called without roll being called first :)
public static int lastRoll = -1;
//sets die to have numSides number of sides
public Die(int numSides) {
sides = numSides;
}
//defines Die as having 6 sides if not stated when calling it
public Die() {
sides = 6;
}
//returns number of sides of the die (6 if not explicitly stated)
public int numSides() {
return sides;
}
//Sets static int lastRoll and returns it's value (so doesnt return -1 anymore)
public int roll() {
lastRoll = (int)((Math.random() * sides) + 1);
return lastRoll;
}
//returns last roll(will be -1 if roll() is not called)
public static int readLastRoll() {
return lastRoll;
}
}