/** * Concrete strategy to compute the area of a rectangular shape: knows its own width * and height and how to compute its area. * @author Dung X. Nguyen *

* Copyright 1999 by Dung X. Nguyen - Al rights reserved. */ public class Rectangle extends AShape { private double _height; private double _width; /** * Initializes this Rectangle width a given width and a given height * @param width width of this Rectangle, >= 0. * @param height height of this Rectangle, >= 0. * @exception IllegalArgumentException, if params do not satisfy preconditions. */ public Rectangle(double width, double height) { if (width < 0 || height < 0) { throw new IllegalArgumentException ("Rectangle.Rectangle (width, height): width < 0) or height <0."); } _height = height; _width = width; } /** * @returns this Rectangle's area. */ public double getArea() { return _height * _width; } /** * @returns a String describing a Rectangle with its width and height. */ public String toString () { return "Rectangle (width = " + _width + ", heigth = " + _height + ")"; } }