Question: Compare and contrast a design where Octagon extends GeometricObject and implements Comparable with one in which there is no GeometricObject parent class and no Comparable
Compare and contrast a design where Octagon extends GeometricObject and implements Comparable with one in which there is no GeometricObject parent class and no Comparable interface incorporated.
What are the advantages and disadvantages of both designs?
here is the code for geometric object:
1 public class TestGeometricObject {
2 /** Main method */ 3 public static void main(String[] args) { 4 // Create two geometric objects 5 GeometricObject geoObject1 = new Circle(5); 6 GeometricObject geoObject2 = new Rectangle(5, 3); 7 8 System.out.println("The two objects have the same area? " + 9 equalArea(geoObject1, geoObject2)); 10 11 // Display circle 12 displayGeometricObject(geoObject1); 13 14 // Display rectangle 15 displayGeometricObject(geoObject2); 16 } 17 /** A method for comparing the areas of two geometric objects */ equalArea 19 public static boolean equalArea(GeometricObject object1, 20 GeometricObject object2) { 21 return object1.getArea() == object2.getArea(); 22 } 23 24 /** A method for displaying a geometric object */ displayGeometricObject 25 public static void displayGeometricObject(GeometricObject object) { 26 System.out.println(); 27 System.out.println("The area is " + object.getArea()); 28 System.out.println("The perimeter is " + object.getPerimeter()); 30 }
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
