Using the Dice class
Class :
Dice
The
Object : any number
dice
Methods
or Operations:
int roll()
returns
an integer, the sum of the spots on all the dice
Declaration
and initialization:
1.
Dice d =new Dice();
//
d is a dice object i.e.two
dice
2. Dice x = new Dice(3);
// x
is a dice object (3 dice)
3.
Dice y = new Dice(1)
//
y is a single die etc.
Example:
Dice d = new Dice(3); // we will be using 3 dice System.out.println("Roll of three dice is: " + d.roll());