Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Die {
- private int faceValue;
- private int numFaces;
- /*
- * Default die is 6 sided
- * */
- public Die(){
- faceValue=0;
- numFaces=6;
- }
- public Die(int faces){
- faceValue=0;
- numFaces=faces;
- }
- public void rollDie(){
- faceValue=(int)(Math.random()*numFaces)+1;
- }
- public int rollNumTimes(int times){
- int rollSum=0;
- for(int i=0; i<times; i++){
- rollDie();
- rollSum= rollSum+faceValue;
- }
- return rollSum;
- }
- public int getFaceValue() {
- return faceValue;
- }
- public void setFaceValue(int faceValue) {
- this.faceValue = faceValue;
- }
- public int getNumFaces() {
- return numFaces;
- }
- public void setNumFaces(int numFaces) {
- this.numFaces = numFaces;
- }
- @Override
- public String toString() {
- return "Die{" +
- "faceValue=" + faceValue +
- ", numFaces=" + numFaces +
- '}';
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement