Roll the dice (Java program) | CramShark | Welcome to the Paradise Roller application java | Scoop.it
Roll the dice (Java program) Solution

 

If the user chooses to roll the dice, the application rolls two six-sided dice, displays the results of each, and asks if the user wants to roll again.

Specifications
• Create a class named Die to store the data about each die. This class should contain these constructors and methods:
public Die() // default to a six-sided die
public Die(int sides) // allow a variable number of sides
public void roll()
public int getValue()

using Math class to generate a random number from 1 to the number of sides.


It should look this after :

Welcome to the Paradise Roller application

Roll the dice? (y/n): y

Roll 1:
2
5
Craps!

Roll again? (y/n): y

Roll 2:
2
1

Roll again? (y/n): y

Roll 3:
4
6

Roll again? (y/n): y

Roll 4:
6
6
Box cars!

Roll again? (y/n): y

Roll 5:
1
1
Snake eyes!

Roll again? (y/n): n


Via CramShark