-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDie.java
More file actions
29 lines (24 loc) · 696 Bytes
/
Die.java
File metadata and controls
29 lines (24 loc) · 696 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
29
import java.util.*;
import java.lang.*;
import java.io.*;
public class Die { //defines one Die object
private int n; //number of faces
private int faceValue; //the number that is showing
private Random rand; //a randomizer
//constructor uses parameter n to create an n-sided die
public Die(int n) {
this.n = n;
this.rand = new Random();
}
//getter method to access the faceValue
public int getFaceValue() {
return faceValue;
}
//setter method to change the number of faces of the die
public void setN(int n) {
this.n = n;
}
public void roll() {
faceValue = rand.nextInt(n)+1;
}
}