Add EightDie
This commit is contained in:
parent
f38c25748b
commit
36da98836d
32
Project/EightDie.java
Normal file
32
Project/EightDie.java
Normal file
@ -0,0 +1,32 @@
|
||||
import java.util.*;
|
||||
|
||||
public class EightDie extends MyDie implements Comparable {
|
||||
|
||||
public EightDie() {
|
||||
// set default values
|
||||
myValue = (int) (Math.random()*8)+1;
|
||||
rand = new Random();
|
||||
}
|
||||
|
||||
public void roll () {
|
||||
myValue = rand.nextInt(8) + 1;
|
||||
}
|
||||
|
||||
public int getValue() {
|
||||
return myValue;
|
||||
}
|
||||
|
||||
|
||||
// set the random number generator seed for testing
|
||||
public void setSeed(int seed) {
|
||||
rand.setSeed(seed);
|
||||
|
||||
}
|
||||
|
||||
// allows dice to be compared if necessary
|
||||
public int compareTo(Object o) {
|
||||
EightDie d = (EightDie) o;
|
||||
return getValue() - d.getValue();
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user