import java.awt.Graphics;

/**
 * This class implements a square, which is defined by a upper-left corner,
 * plus a width and a height.
 * @author fpereira
 *
 */
public class Rectangle implements Shape {
  /**
   * The X coordinate of the upper-left corner.
   */
  private int x = 0;

  /**
   * The Y coordinate of the upper-left corner.
   */
  private int y = 0;

  /**
   * The width of the square.
   */
  private int w = 0;

  /**
   * The height of the square.
   */
  private int h = 0;

  /**
   * The constructor.
   * @param xp The X coordinate of the upper-left corner.
   * @param yp The Y coordinate of the upper-left corner.
   * @param wp The width of the square.
   * @param hp The height of the square.
   */
  public Rectangle(final int xp, final int yp, final int wp, final int hp) {
    this.x = xp;
    this.y = yp;
    this.w = wp;
    this.h = hp;
  }

  /**
   * This method sets the width of the rectangle.
   * @param newW the new width.
   */
  public void setWidth(int newW) {
    this.w = newW;
  }

  /**
   * This method sets the height of the rectangle.
   * @param newH the new height.
   */
  public void setHeight(int newH) {
    this.h = newH;
  }

  /**
   * This method gives the area of the rectangle.
   * @return an integer representing the width times the height of the
   * rectangle.
   */
  public int area() {
    return w * h;
  }

  /**
   * Draws the rectangle on the screen.
   * @param c the graphics object responsible for renderizing this shape.
   */
  public final void draw(final Graphics c) {
    c.drawRect(x, y, w, h);
  }
}
