1  public class PolygonTest {
  2  
  3  	public static void main(String[] args) {
  4  	
  5  		// Constants:
  6  		double w = 3, h = 4;
  7  		Dimension d = new Dimension(w, h);
  8  		double t = Math.PI/3;
  9  		
 10  		// An array of polygons:
 11  		int numPolys = 12;
 12  		Polygon[] polygon = new Polygon[numPolys];
 13  		
 14  		// Temporary variables:
 15  		Square square = new Square();
 16  		Rectangle rectangle = new Rectangle(); 
 17  		Parallelogram parallelogram = new Parallelogram();
 18  
 19  		// Two squares:
 20  		polygon[0] = new Square(w);
 21  		square.setWidth(w); polygon[1] = square;
 22  		// Five rectangles:
 23  		polygon[2] = new Rectangle(w, h);
 24  		rectangle.setWidth(w); rectangle.setHeight(h); polygon[3] = rectangle; 
 25  		rectangle.setDimension(w, h); polygon[4] = rectangle;
 26  		polygon[5] = new Rectangle(d);
 27  		rectangle.setDimension(d); polygon[6] = rectangle; 
 28  		// Five parallelograms:
 29  		polygon[7] = new Parallelogram(w, h, t);
 30  		polygon[8] = new Parallelogram(d, t);
 31  		parallelogram.setWidth(w); parallelogram.setHeight(h); 
 32  		parallelogram.setAngle(t); polygon[9] = parallelogram;
 33  		parallelogram.setDimension(w, h); polygon[10] = parallelogram;
 34  		parallelogram.setDimension(d); polygon[11] = parallelogram;
 35  		
 36  		double perimeter, area;
 37  		
 38  		for (int i = 0; i < polygon.length; i++) {
 39  			perimeter = polygon[i].perimeter();
 40  			area = polygon[i].area();
 41  			System.out.print("Polygon " + i);
 42  			System.out.print(", perimeter = " + perimeter);
 43  			System.out.println(", area = " + area);
 44  		}
 45  
 46  	}
 47  	
 48  }