public class PolygonTest { public static void main(String[] args) { // Constants: double w = 3, h = 4; Dimension d = new Dimension(w, h); double t = Math.PI/3; // An array of polygons: int numPolys = 12; Polygon[] polygon = new Polygon[numPolys]; // Temporary variables: Square square = new Square(); Rectangle rectangle = new Rectangle(); Parallelogram parallelogram = new Parallelogram(); // Two squares: polygon[0] = new Square(w); square.setWidth(w); polygon[1] = square; // Five rectangles: polygon[2] = new Rectangle(w, h); rectangle.setWidth(w); rectangle.setHeight(h); polygon[3] = rectangle; rectangle.setDimension(w, h); polygon[4] = rectangle; polygon[5] = new Rectangle(d); rectangle.setDimension(d); polygon[6] = rectangle; // Five parallelograms: polygon[7] = new Parallelogram(w, h, t); polygon[8] = new Parallelogram(d, t); parallelogram.setWidth(w); parallelogram.setHeight(h); parallelogram.setAngle(t); polygon[9] = parallelogram; parallelogram.setDimension(w, h); polygon[10] = parallelogram; parallelogram.setDimension(d); polygon[11] = parallelogram; double perimeter, area; for (int i = 0; i < polygon.length; i++) { perimeter = polygon[i].perimeter(); area = polygon[i].area(); System.out.print("Polygon " + i); System.out.print(", perimeter = " + perimeter); System.out.println(", area = " + area); } } }