/* * Author: CHEN Yongyuan (Walter) 1930006025 from OOP(1007) * Date: 2022/03/27 * Description: This is the class of Circle. */ public class Circle extends Shape { private double radius; /** * Constructor of Circle. * * @param x the x coordinate of the center of the circle * @param y the y coordinate of the center of the circle * @param radius the radius of the circle */ public Circle(double x, double y, double radius) { super(x, y); this.radius = radius; } /** * Get the area of the circle. * * @return the area of the circle */ @Override public double area() { return Math.PI * radius * radius; } /** * Test */ public static void testCircle() { Circle c1 = new Circle(1.0, 2.0, 3.0); System.out.println(c1.getX() == 1.0); System.out.println(c1.getY() == 2.0); System.out.println(compare(c1.area(), 28.274333882308138)); } /** * Compare two double numbers. * * @param a * @param b * @return true if a and b are equal, false otherwise */ public static boolean compare(double a, double b) { return Math.abs(a - b) < 0.000001; } /** * toString */ @Override public String toString() { return this.getClass().getName() + " has area " + area(); } }