Created
October 17, 2009 11:38
-
-
Save rotespferd/212324 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Random; | |
public class Dice { | |
//Number of sides of the dice | |
private int sides; | |
//First number of the dice | |
private int firstNumber; | |
//Last number of the dice | |
private int lastNumber; | |
//Array of numbers of the dice | |
private int[] numbers; | |
private Random random; | |
/** | |
* @param sides | |
* @param firstNumber | |
* @param lastNumber | |
*/ | |
public Dice(int sides, int firstNumber, int lastNumber) { | |
super(); | |
this.sides = sides; | |
this.firstNumber = firstNumber; | |
this.lastNumber = lastNumber; | |
this.random = new Random(); | |
} | |
public void init() { | |
this.numbers = new int[this.sides]; | |
for (int i = 0; i < numbers.length; i++) { | |
this.numbers[i] = i + this.firstNumber; | |
} | |
} | |
public int rollDice() { | |
int out; | |
out = random.nextInt(lastNumber) + 1; | |
return out; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment