/** A rectangle implements the getArea method. This satisfies * the Measurable interface, so rectangles can be instantiated. * * Taken from Core Web Programming from * Prentice Hall and Sun Microsystems Press, * http://www.corewebprogramming.com/. * © 2001 Marty Hall and Larry Brown; * may be freely used or adapted. */ public class Rectangle extends Polygon { private double width, height; public Rectangle(int x, int y, double width, double height) { setNumSides(2); setX(x); setY(y); setWidth(width); setHeight(height); } public double getWidth() { return(width); } public void setWidth(double width) { this.width = width; } public double getHeight() { return(height); } public void setHeight(double height) { this.height = height; } /** Required to implement Measurable interface. */ public double getArea() { return(width * height); } }