
/**
 * A program to test out the Measurable interface. This version uses only the
 * two abstract methods -- getArea and getPerimeter.
 *
 * @author Mark Young (A00000000)
 */
public class MeasuringStuff {

    public static void main(String[] args) {
        // create the shapes
        Circle c1 = new Circle(10.0);
        Circle c2 = new Circle(24.7);
        Rectangle r1 = new Rectangle(10.0, 20.0);
        Rectangle r2 = new Rectangle(0.4, 1000.0);

        // print out their basic information
        printCircleInfo("c1", c1);
        printCircleInfo("c2", c2);
        printRectangleInfo("r1", r1);
        printRectangleInfo("r2", r2);

        // print out their measurable information
        printMeasurableInfo("c1", c1);
        printMeasurableInfo("c2", c2);
        printMeasurableInfo("r1", r1);
        printMeasurableInfo("r2", r2);

        // print out their roundnesses
        System.out.println("The roundness of c1 is " + roundness(c1));
        System.out.println("The roundness of c2 is " + roundness(c2));
        System.out.println("The roundness of r1 is " + roundness(r1));
        System.out.println("The roundness of r2 is " + roundness(r2));
    }

    // this method accepts Circles, but not Rectangles
    private static void printCircleInfo(String name, Circle circ) {
        System.out.println(name + " is a circle of radius " + circ.getRadius());
    }

    // this method accepts Rectangles, but not Circles
    private static void printRectangleInfo(String name, Rectangle rect) {
        System.out.println(name + " is a " + rect.getLength() + "x" 
                + rect.getWidth() + " rectangle");
    }

    // this method accepts any object that implements the Measurable interface
    // which includes both Circles and Rectangles
    private static void printMeasurableInfo(String name, Measurable m) {
        System.out.println("Measures of " + name + ":");
        System.out.println("\tArea:       " + m.getArea());
        System.out.println("\tPerimeter:  " + m.getPerimeter());
    }

    // this method likewise accepts any Measurable object
    private static double roundness(Measurable m) {
        return 4 * Math.PI * m.getArea() / Math.pow(m.getPerimeter(), 2);
    }

}

