/* * Author: CHEN Yongyuan (Walter) 1930006025 from OOP(1007) * Date: 2022/03/27 * Description: This is the Rectangle class. */ public class Rectangle extends Shape { private double width; private double height; /** * Constructor * * @param x the x coordinate of the center of the rectangle * @param y the y coordinate of the center of the rectangle * @param width the width of the rectangle * @param length the length of the rectangle */ public Rectangle(double x, double y, double width, double length) { super(x, y); this.width = width; this.height = length; } /** * Override the area method * * @return double */ @Override public double area() { return width * height; } /** * Test */ public static void testRectangle() { Rectangle r1 = new Rectangle(1.0, 2.0, 3.0, 4.0); System.out.println(r1.getX() == 1.0); System.out.println(r1.getY() == 2.0); System.out.println(r1.area() == 12.0); } }