Question: Problem: Compare areas of different geometric shapes (filename: CompareShapeAreas.java ) Define a class named ComparableCircle that extends the Circle class and implements the Comparable interface
Problem: Compare areas of different geometric shapes
(filename: CompareShapeAreas.java)
Define a class named ComparableCircle that extends the Circle class and implements the Comparable interface as shown below. The Circle class itself extends the GeometricObject class.
class ComparableCircle extends Circle implements Comparable
Implement the CompareTo method defined inside the Comparable interface to compare the areas between a Circle object and a GeometricObject object. It returns 1 if the circle has a larger area, else if the circle has a smaller area, it returns -1, else it returns 0.
For implementing the Geometric class and the Circle class, you may use the code from the book or the slides
Similarly, based on the code from the book or the slides, define a class named ComparableRectangle that extends the Rectangle class and implements the Comparable interface. The Rectangle class itself extends the GeometricObject class. Implement the CompareTo method defined inside the Comparable interface to compare the areas between a Rectangle object and a GeometricObject object. It returns 1 if the rectangle has a larger area, else if the rectangle has a smaller area, it returns -1, else it returns 0.
Write a test class to find the larger of two instances of ComparableCircle objects by invoking the CompareTo method, and the larger between an instance of a ComparableCircle and an instance of ComparableRectangle also by invoking the CompareTo method.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
