Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1 . Declare the headers ( class declaration ) for the classes in the class diagram. 2 . Declare no - argument constructors for Shape,

1. Declare the headers(class declaration) for the classes in the class diagram.
2. Declare no-argument constructors for Shape, TwoDimensionalShape, and
ThreeDimensionalShape classes.
3. Declare the instance variables for Circle(radius), Square(side), Sphere(radius) and
Cube(side) classes. 4. Declare one-argument and no-argument constructors for Circle, Square, Sphere,
and Cube classes.
5. Declare get and set methods for instance variables in Circle, Square, Sphere, and
Cube classes
6. Declare computeArea method for Circle, Square, Sphere, and Cube classes.
7. Declare toString methods for all the classes. Class Shapes toString method should
return the string Shape. The toString method of each of the subclasses in the
hierarchy should return a string containing the classs name the string is a and the
result of a call the superclasss toString method.
8. Write a separate driver class(application class) that creates one object of each of
the classes Circle, Square Sphere and Cube, and invokes their toString methods.
The output for each object should show the is-a relationships between that objects
class and its superclasses.Sample Output:
Circle: Circle is a TwoDimesnionalShape is a Shape
Circle's area is 4.91
Square: Square is a TwoDimesnionalShape is a Shape
Square's area is 6.25
Sphere: Sphere is a ThreeDimesnionalShape is a Shape
Sphere's area is 176.71
Sphere's volume is 220.89
Cube: Cube is a ThreeDimesnionalShape is a Shape
Cube's area is 150.00
Cube's volume is 125.00
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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

Students also viewed these Databases questions