
/**
 * A class that implements the Measurable interface. This class represents a
 * circle.
 *
 * @author Mark Young(A00000000)
 */
public class Circle implements Measurable {

    private double radius;

    /**
     * Create a circle with the given radius.
     *
     * @param reqRad the requested radius
     */
    public Circle(double reqRad) {
        requirePositive("radius", reqRad);
        radius = reqRad;
    }

    /**
     * Get this circle's radius.
     *
     * @return this circle's radius
     */
    public double getRadius() {
        return radius;
    }

    /**
     * Get this circle's circumference.
     *
     * @return this circle's circumference
     */
    public double getCircumference() {
        return 2 * Math.PI * radius;
    }

    /**
     * Get this circle's diameter.
     *
     * @return this circle's diameter
     */
    public double getDiameter() {
        return 2 * radius;
    }

    @Override
    public double getArea() {
        return Math.PI * Math.pow(radius, 2);
    }

    @Override
    public double getPerimeter() {
        return getCircumference();
    }

    @Override
    public String toString() {
        return "Circle(r = " + radius + ")";
    }

    @Override
    public boolean equals(Object obj) {
        return (obj instanceof Circle that) && that.radius == this.radius;
    }

    // ---------- private methods ---------- //
    /**
     * Require that the given dimension be positive.
     *
     * @param dim the name of the dimension
     * @param value the value requested for that dimension
     * @throws IllegalArgumentException if {@code value} is not positive
     */
    private static void requirePositive(String dim, double value) {
        if (value <= 0.0) {
            throw new IllegalArgumentException(dim + ": " + value);
        }
    }

}
