Question: Create a Java Dice Rolling program with NetBeans that satisfies the specifications below. Dice rolling project Sample Console Output Welcome to the Paradise Roller Roll

Create a Java Dice Rolling program with NetBeans that satisfies the specifications below.

Dice rolling project

Sample Console Output

Welcome to the Paradise Roller

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

Operation

  • 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 public class named DiceRollerApp that has the main method and uses the PairOfDice class to roll the dice each time the user responds y to the request prompts. This app class should display special messages for craps (sum of both dice is 7), snake eyes (double 1s), and box cars (double 6s). For this application, assume that two six-sided dice are used.
  • Create a public class named Die to store the data for a single die. The class will have two state instance variables: # of sides and Value (face value of die once it is rolled). This class will 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() // roll die to determine its value using a random method public int getValue()

  • Create a public class named PairOfDice to store two dice. This class should contain two instance variables of the Die class type, an instance variable that holds the sum of the two dice, and these constructors and methods:

public PairOfDice() // default to two six-sided dice public PairOfDice(int sides) // allow a variable number of sides for the two die public void roll() // call each Die objects roll method public int getValue1() // get value of die1 public int getValue2() // get value of die2 public int getSum() // get the sum of both dice

  • You can use the random method of the Math class to generate a random number from 1 to the number of sides on a die like this:

int value = (int) (Math.random() * sides);

Notes:

Do not add additional methods to the Die or PairOfDice classes. The data about the rolls are not being stored so there is no need to create an array. Remember to keep the methods simple. The methods should be designed to do one thing only. This helps the classes and methods have high cohesion . You can write test code to test the methods of the Die class before creating the PairOfDice class but remember to remove it from the program because only the PairOfDice class is called from the DiceRollerApp class.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!