// The Rectangle class is augmented with a draw method.
// Barry Cornelius, 20 June 2000
import java.awt. Color;
import java.awt. Graphics;
public class Rectangle extends Shape
{
   private int iWidth;
   private int iHeight;
   public Rectangle(final int pWidth, final int pHeight,
                    final int pX, final int pY)
   {
      super(pX, pY);
      iWidth = pWidth;
      iHeight = pHeight;
   }
   public Rectangle()     { this(0, 0, 0, 0); }
   public int getWidth()  { return iWidth; }
   public int getHeight() { return iHeight; }
   public boolean equals(final Object pObject)
   { 
      if ( pObject==null || getClass()!=pObject.getClass() )
      {
         return false;
      }
      return super.equals(pObject) 
             && iWidth==((Rectangle)pObject).iWidth
             && iHeight==((Rectangle)pObject).iHeight;
   }
   public int hashCode() { return super.hashCode() + iWidth + iHeight; }
   public String toString()
   {
      return super.toString() + ":" + iWidth + ":" + iHeight;
   }
   public void draw(final Graphics pGraphics)
   {
      final int tXLeft = getX() - iWidth/2;
      final int tYTop = getY() - iHeight/2;
      pGraphics.setColor(Color.green);
      pGraphics.drawRect(tXLeft, tYTop, iWidth, iHeight);
   }
}
