Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

Business Process Driven Database Design With Oracle PL SQL

Authors: Rajeev Kaula

1st Edition

1795532386, 978-1795532389

More Books

Students also viewed these Databases questions