Question: 1. Write a default constructor for Toy that will set its weight to 0 and its dimensions to a default Dimension object. In other words,

1. Write a default constructor for Toy that will set its weight to 0 and its dimensions to a default Dimension object. In other words, for that second part, you will use the default constructor for Dimension to create it.

2. Write a non-default constructor for Toy that will set its width, height, length, and weight to values passed in to the constructor. Notice that setting the width, height, and length will involve creating a Dimension object. Assume you have written a setWeight function for Toy already that ensures that the weight is not set to a negative value.

class Dimension { private double height; private double width; private double length; public Dimension() { height = 0; width = 0; length = 0; } public void setHeight(double height) { if(height < 0){ height = height * -1; } this.height = height; } @Override public String toString() { return "Dimension{" + "height=" + height + ", width=" + width + ", length=" + length + '}'; } } abstract class Toy { private Dimension dimensions; private double weight; public String getType() { return "Toy"; } abstract public void play(); }

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!