/* * @topic T02365 11/29/2012 Polymorphism * @brief Creates array of Shapes, computes total area of Shapes */ package interfacedemo; public class Main { public static void main(String[] args) { Shape[] drawing = new Shape[7]; drawing[0] = new Circle(5); drawing[1] = new Circle(15); drawing[2] = new Rectangle(20, 30); drawing[3] = new Rectangle(25, 30); drawing[4] = new Rectangle(26, 30); drawing[5] = new Rectangle(27, 30); drawing[6] = new Rectangle(28, 30); int idx = 0; double totalArea = 0.0; for (; idx < drawing.length; ++idx) { drawing[idx].draw(); totalArea += drawing[idx].getArea(); } System.out.println("Total Area is " + totalArea); }//main }// class Main /* Output: Cirlcle with area 78.53981633974483 Cirlcle with area 706.8583470577034 Rectangle with area 600.0 Rectangle with area 750.0 Rectangle with area 780.0 Rectangle with area 810.0 Rectangle with area 840.0 Total Area is 4565.398163397448 */