forked from tlu21545/Java_Challenge_2022
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDie.java
More file actions
36 lines (35 loc) · 999 Bytes
/
Die.java
File metadata and controls
36 lines (35 loc) · 999 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
public class Die{
//Stores number of sides die has
private int numSides;
//Store what number the die has rolled
private int rolledNum;
//Basic die constructor
public Die(){
}
//Die constructor when inputed the sides of the die
public Die(int sidesOfDie){
setNumSides(sidesOfDie);
}
//Returns the number of sides the die has
public int numSides(){
return numSides;
}
//Rolls the die and stores it in rolled num. rolled num is returned
public int roll(){
rolledNum = (int)(Math.random()*numSides) + 1;
return rolledNum;
}
//Returns the last roll given by the user to the program if rolled num does not have a value then -1 is returned
public int readLastRoll(){
if(rolledNum > 0){
return rolledNum;
}
else{
return -1;
}
}
//sets the num of sides the die has
public void setNumSides(int sides){
numSides = sides;
}
}