public class Exercise14_8 { public static void main(String[] args) { new Exercise14_8(); } public Exercise14_8() { GeometricObject[] a = {new Circle(5), new Circle(6), new Rectangle(2, 3), new Rectangle(2, 3)}; System.out.println("The total area is " + sumArea(a)); } public static double sumArea(GeometricObject[] a) { double sum = 0; for (int i = 0; i < a.length; i++) sum += a[i].getArea(); return sum; } // Rectangle.java: The Rectangle class that extends GeometricObject class Rectangle extends GeometricObject { private double width; private double height; /** Construct a rectangle with width and height */ public Rectangle(double width, double height) { this.width = width; this.height = height; } /**Return width*/ public double getWidth() { return width; } /**Set a new width*/ public void setWidth(double width) { this.width = width; } /**Return height*/ public double getHeight() { return height; } /**Set a new height*/ public void setHeight(double height) { this.height = height; } /**Implement the getArea method in GeometricObject*/ public double getArea() { return width*height; } /**Implement the getPerimeter method in GeometricObject*/ public double getPerimeter() { return 2*(width + height); } /**Override the equals method defined in the Object class*/ public boolean equals(Rectangle rectangle) { return (width == rectangle.getWidth()) && (height == rectangle.getHeight()); } /**Override the toString method defined in the Object class*/ public String toString() { return "[Rectangle] width = " + width + " and height = " + height; } } }