Question
Write a Rectangle class that has two instance variables: length and width of the rectangle (both are floating-point numbers). The class should have two constructors:
Write a Rectangle class that has two instance variables: length and width of the rectangle (both are floating-point numbers). The class should have two constructors: one with two parameters for the two instance variables, and a no-argument constructor (set both instance variables to zero). Include the following:
Three accessor methods: one to return the length, one to return the width and one called computeArea that returns the area of the rectangle.
Two mutator methods: one to set the value of the length and the other to set the value of the width.
Then write another class called Cuboid that is derived from Rectangle and has an additional instance variable: height of the cuboid. This class also has two constructors: one with three parameters for the three instance variables, and a no-argument constructor (set all instance variables to zero). The class also includes:
Two accessor method: one that returns the height of the cuboid and one called computeVolume that returns the volume of the cuboid.
A mutator method that set the value of the heigth.
Override the computeArea to return the area of the cuboid.
Finally, write a driver program that tests the two classes and all the methods in both classes.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started