Part 1: Abstract Classes 1. Copy the source files of Circle, Rectangle and GeometricObject classes (located in LabFiles folder) and paste them in the default package (You may need to fix any problems related to package declaration). 2. Open Circle, Rectangle and GeometricObject classes using NetBeans editor and go through the classes’ implementation. 3. In the GeometricObject class add two methods called respectively getArea() and getPerimeter(). Discuss: 1. Is the area formula of a circle similar to area formula of a rectangle? Since: GeometricObject is the superclass of Circle and Rectangle, and getArea() method is a
Part 1: Abstract Classes
1. Copy the source files of Circle, Rectangle and GeometricObject classes (located in
LabFiles folder) and paste them in the default package (You may need to fix any
problems related to package declaration).
2. Open Circle, Rectangle and GeometricObject classes using NetBeans editor and go
through the classes’ implementation.
3. In the GeometricObject class add two methods called respectively getArea() and
getPerimeter().
Discuss:
1. Is the area formula of a circle similar to area formula of a rectangle?
Since:
GeometricObject is the superclass of Circle and Rectangle, and getArea() method is a
common method in both Circle and Rectangle classes.
Then:
2. Should you define the getArea() method in the superclass GeometricObject? Or in
the subclasses Circle and Rectangle?
3. If yes, Should the getArea() method be declared as abstract method in the
superclass GeometricObject? Or as instant method?
4. Is declaring getArea() as abstract, would solve the problem of having two different
area formulas for Circle and Rectangle?
5. If getArea() is declared as abstract in GeometricObject, should GeometricObject
class be declared as abstract class?
Now apply the same discussion to getPerimeter() method.
4. Modify the class GeometricObject to be abstract class as well as the methods getArea()
and getPerimeter(). Apply the required changes in the class’s header and methods’
header. See the UML class diagrams in next page.
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 1 images