-
Notifications
You must be signed in to change notification settings - Fork 0
/
Die.java
61 lines (54 loc) · 1.28 KB
/
Die.java
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
58
59
60
61
/**
* Representation of a {@link Yahtzee#DICE_SIDES} sided dice.
*
* @see Yahtzee#DICE_SIDES
* @author Arjun Subramanian
*/
public class Die {
private int value;
/**
* Construct an instance of {@link Die} with {@link #value} set to {@code 0}.
*/
public Die() {
value = 0;
}
/**
* Getter for the {@link Die}'s {@link #value}.
*
* NOTE: The score might be {@code 0} if unset.
*
* @return The current {@link #value}.
*/
public int getValue() {
return value;
}
/**
* Setter for the {@link Die}'s {@link #value}.
*
* @param v New value for the die.
*/
public void setValue(int v) {
value = v;
}
/**
* Randomize the {@link #value} from {@code 1} to {@link Yahtzee#DICE_SIDES}.
*/
public void roll() {
value = (int) (Math.random() * Yahtzee.DICE_SIDES) + 1;
}
/**
* Returns the {@link Die#value} as a String.
*
* @return String representation of {@link Die}.
* @see java.lang.Object#toString()
*/
public String toString() {
return Integer.toString(value);
}
/**
* Print the {@link #toString()} to System.out.
*/
public void display() {
System.out.println(this.toString());
}
}