Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1. Using the Die class defined and modified in class, design and implement a class called PairOfDice, composed of two Die objects as instance data.

1. Using the Die class defined and modified in class, design and implement a class called PairOfDice, composed of two Die objects as instance data. The class should include the following methods: A non-default constructor, i.e. with parameters A setter method for each instance data A getter method for each instance data A method roll() that rolls both dice A toString() method that returns a string containing the colors of both dice, eg Colors of both dice: Red, Blue A method pairSum that returns the current sum of the two die values. A method equals() that compares two pairs of dice and returns true, if each pair contains dice with same color and face value. For example, if the first pair contains dice with color/faceValue: Red/5, Blue/3 and second pair contains dice with color/faceValue: Blue/3, Red/5, the method will return true. If the first pair contains dice with color/faceValue: Red/5, Blue/3 and second pair contains dice with color/faceValue: Blue/5, Red/5, the method will return false.

2. Write an application TestPairOfDice that uses the PairOfDice class to create two pair of dice. The application prints to the screen the sum of the face value of the dice inside the first pair. The program then rolls the second pair and prints to the screen the information about each pair. Lastly, the program to the screen whether the two pairs are equal or not.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

Do This: Consider the following method. Complete the trace table fo

Answered: 1 week ago