forked from Denisolt/CSCI-160
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDie1.java
More file actions
57 lines (46 loc) · 1008 Bytes
/
Die1.java
File metadata and controls
57 lines (46 loc) · 1008 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
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.Random;
/**
The Die class simulates a six-sided die.
*/
public class Die1
{
private int sides; // Number of sides
private int value; // The die's value
/**
The constructor performs an initial
roll of the die.
@param numSides The number of sides for this die.
*/
public Die1(int numSides)
{
sides = numSides;
roll();
}
/**
The roll method simlates the rolling of
the die.
*/
public void roll()
{
// Create a Random object.
Random rand = new Random();
// Get a random value for the die.
value = rand.nextInt(sides) + 1;
}
/**
getSides method
@return The number of sides for this die.
*/
public int getSides()
{
return sides;
}
/**
getValue method
@return The value of the die.
*/
public int getValue()
{
return value;
}
}