Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need help with these Java programming assignements. public class Die { //here you declare your attributes private int faceValue; //operations //constructor - public Die()

I need help with these Java programming assignements.

public class Die { //here you declare your attributes private int faceValue; //operations //constructor - public Die() { //body of constructor faceValue=(int)(Math.random()*6)+1;//instead of 1, use random approach to generate it } //roll operation public void roll() { faceValue=(int)(Math.random()*6)+1; } //add a getter method public int getFaceValue() { return faceValue; } //add a setter method public void setFaceValue(int value) { faceValue=value; } //add a toString() method public String toString() { String result = Integer.toString(faceValue);

return result; }

}

1.Modify the class Die presented above to include another instance data (string) called color to represent the color of a die.Add a getter/setter for this data.

2.. Implement a method comboDie that takes two dice parameters. The method returns a die with color the combination of both dice colors and face value the average of the dice facevalues. (Add this method to your MyMethods class)

Example: if first die is blue with facevalue=3 and second die is redwith facevalue=5, the method returns a blue-red die with facevalue=4. Note.

Use the Die class presented above.

3. Using the Die class defined above, design and implement a class called PairOfDice, composed of two Die objects. Include methods to set and get each individual die, a method to roll the dice, a toString method that returns colors of both dice and a method pairSum that returns the current sum of the two die values.

4.Write an application TestPairOfDice that uses the PairOfDice class to create and roll a pair of dice 1000 times, counting the number of box cars (two sixes) that occur..

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored 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

Recommended Textbook for

Advanced Database Systems

Authors: Carlo Zaniolo, Stefano Ceri, Christos Faloutsos, Richard T. Snodgrass, V.S. Subrahmanian, Roberto Zicari

1st Edition

155860443X, 978-1558604438

More Books

Students also viewed these Databases questions