Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Random;
- /**
- * Write a description of class Die here.
- *
- * @author (your name)
- * @version (a version number or a date)
- */
- public class Die implements DieInterface
- {
- private static Random randomiser;
- private Integer value; // null if unrolled
- public Die()
- {
- value = 0;
- if(!(randomiser instanceof Random)){
- randomiser = new Random();
- }
- }
- public boolean hasRolled(){
- if(value != 0){
- return true;
- }
- else{
- return false;
- }
- }
- public void roll(){
- value = randomiser.nextInt(NUMBER_OF_SIDES_ON_DIE) + 1;
- }
- public int getValue()throws NotRolledYetException{
- if(hasRolled()){
- return value;
- }
- else{
- throw new NotRolledYetException("You haven't rolled the DIE");
- }
- }
- public void setValue(int value){
- if(1 <= value && value <= NUMBER_OF_SIDES_ON_DIE){
- this.value = value;
- }
- else{
- this.value = 0;
- }
- }
- public void clear(){
- value = 0;
- }
- public void setSeed(long seed){
- randomiser.setSeed(seed);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement