public class ArrayShapes2
{
   public static void main(String[] args)
   {
     Shape[] shapes = new Shape[5];      // array of shapes
     shapes[0] = new Circ(1, 2, 3);      // creating 3 circles
     shapes[1] = new Circ(1, 3, 5);
     shapes[2] = new Circ(5, 6, 11);

     shapes[3] = new Rect(3, 5, 6, 2);   // creating 2 rectangles
     shapes[4] = new Rect(5, 7, 2, 2);

     double totalArea = 0;               // the total area of all shapes
     for (int i=0; i<shapes.length; i++) // loop over all shapes
       totalArea += shapes[i].getArea(); //  and and computing the total area

     System.out.println("Total area = " + totalArea);

     double totalCircArea = 0;           // total area of all circles
     double totalRectArea = 0;           // total area of all rectangles
     for (int i=0; i<shapes.length; i++) // loop over all shapes
     {
       if (shapes[i] instanceof Circ)
          totalCircArea += shapes[i].getArea();  // update the area of circles
       else if (shapes[i] instanceof Rect)
          totalRectArea += shapes[i].getArea();  // update the area of rects
     }
     System.out.println("Total area of circles = " + totalCircArea);
     System.out.println("Total area of rectangles = " + totalRectArea);
   }
}
