/** * 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 _dHeight;
private double _dWidth;
/**
* Initializes this Rectangle
width a given width and a given height
* @param dWidth width of this Rectangle
, >= 0.
* @param dHeight height of this Rectangle
, >= 0.
* @exception IllegalArgumentException, if params do not satisfy preconditions.
*/
public Rectangle(double dWidth, double dHeight)
{
if (dWidth < 0 || dHeight < 0)
{
throw new IllegalArgumentException ("Rectangle.Rectangle (width, height): width < 0) or height <0.");
}
_dHeight = dHeight;
_dWidth = dWidth;
}
/**
* @returns this Rectangle
's area.
*/
public double dArea()
{
return _dHeight * _dWidth;
}
/**
* @returns a String describing a Rectangle with its width and height.
*/
public String toString ()
{
return "Rectangle (width = " + _dWidth + ", heigth = " + _dHeight + ")";
}
}