Lab 13
Using the Coins class we looked at in class as a model, implement a Dice
class that models the rolling of dice and determining the dot sum.
Here is the documentation for my Dice class:
Class Dice
java.lang.Object
Dice
public class Dice
- extends
Object
Dice models rolling dice and determining the resulting dot sum.
- Version:
- 02/2009
- Author:
- D. Searls
Constructor Summary |
Dice()
Construct a Dice object that models a single die. |
Dice(int num)
Construct a Dice object that models the specified number of
dice. |
Method Summary |
int |
getDotSum()
Simulate the rolling of the dice and return the resulting dot
sum. |
int |
getNumberOfDice()
Get the number of dice. |
void |
setNumberOfDice(int newNumber)
Set the number of dice to the specified value. |
Methods inherited from class java.lang.Object |
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait |
Dice
public Dice()
- Construct a Dice object that models a single die.
Dice
public Dice(int num)
- Construct a Dice object that models the specified number of dice. If the
specified number is less than or equal to zero, a default object (modeling a single die) will
be constructed.
- Parameters:
num - the specified number of dice.
getDotSum
public int getDotSum()
- Simulate the rolling of the dice and return the resulting dot sum. Note
that successive calls to this method will return different values since each
invocation represents a new simulation of the rolling of the dice.
-
- Returns:
- the dot sum
getNumberOfDice
public int getNumberOfDice()
- Get the number of dice.
-
- Returns:
- the number of dice
setNumberOfDice
public void setNumberOfDice(int newNumber)
- Set the number of dice to the specified value. If the specified number of
dice is less than or equal to zero this method does nothing.
-
- Parameters:
newNumber - the specified number of dice (must be
positive)
|
Submitting Your Work
Submit your Dice.java file as an
attachment to an email message whose subject is "Lab13".