import java.awt.Rectangle;

/**
 * Prints out the area of the intersection of two Rectangles.
 * <p>
 * Because this program uses Rectangles from java.awt, the (0, 0)
 * origin is in the upper left, with x increasing positively to the
 * right and y increasing positively in a downward direction.
 *
 * @author Zach Tomaszewski
 */
public class RectangleIntersection {

  public static void main(String[] args) {

    //build rectangles
    Rectangle big;
    big = new Rectangle(5, 5, 10, 10);
    Rectangle small = new Rectangle(8, 9);

    //print out rectangle details
    System.out.println("I have two rectangles on a screen.");
    System.out.print("The first is at ");
    System.out.print("(" + big.getX() + ", " + big.getY() + ")");
    System.out.print(" with a width of " + big.getWidth());
    System.out.println(" and a height of " + big.getHeight() + ".");
    System.out.print("The second is at ");
    System.out.print("(" + small.getX() + ", " + small.getY() + ")");
    System.out.print(" with a width of " + small.getWidth());
    System.out.println(" and a height of " + small.getHeight() + ".");

    //compute area of intersection
    Rectangle intersectRect;
    intersectRect = big.intersection(small);
    double area = intersectRect.getWidth() * intersectRect.getHeight();
    System.out.print("The area of the intersection of these " +
        "two rectangles is: " + area);
  }

}

