Question: Design and implement these files: A parent/base class called shape with the following: Attributes - name : string Methods Constructor, getName(), toString() Derived class called

Design and implement these files:

  1. A parent/base class called shape with the following:
    1. Attributes - name : string
    2. Methods Constructor, getName(), toString()
  2. Derived class called circle inherits from shape, with the following:
    1. Attributes radius : double
    2. Methods
      1. Constructor
      2. toString
      3. getArea()
  3. Derived class called square inherits from shape, with the following:
    1. Attributes side : double
    2. Methods
      1. Constructor
      2. getArea()
      3. toString
  4. Derived class called sphere inherits from circle, with the following:
    1. Attributes
    2. Methods
      1. Constructor
      2. toString
      3. getVolume()
  5. Derived class called cylinder inherits from circle, with the following:
    1. Attributes height : double
    2. Methods
      1. Constructor
      2. getVolume
      3. toString
  6. Derived class called cube inherits from square, with the following:
    1. Attributes
    2. Methods
      1. Constructor
      2. getVolume
      3. toString

There are two interfaces you need to use. Take the decision to implement them whenever required

  1. Interface Volume
    1. Method - getVolume
  2. Interface Area
    1. Method - getArea
  3. A driver file

To do in driver class:

  1. Create 6 objects of Shape class as an array.
  2. Create objects of every class
  3. Print all the objects
  4. Print the area and volume of different objects

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!