Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Random;
- public class Die {
- private int faceValue;
- private final int MAX=6;
- private Random dieGen; //generator
- public Die()
- {
- faceValue = 1;
- dieGen = new Random();
- }
- //Math.random creates random integers from 1 - 6
- public void roll()
- {
- faceValue = dieGen.nextInt(MAX) +1;
- }
- //Sets the face value
- public void setFaceValue(int value)
- {
- faceValue=value;
- }
- //Gets the face value using the setFaceValue method
- public int getFaceValue()
- {
- return faceValue;
- }
- //Converts values into a String
- public String toString()
- {
- String result = "You rolled a " + faceValue;
- return result;
- }
- }// end class Die
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement