/********************************************************** Main class file: RectMaker.java This file: Rectangle.java Author: CS302 Section 5 Date: 9-26-03 **********************************************************/ /** * The Rectangle class represents a shape defined by * four Points. */ class Rectangle { private Point topLeft; // upper left corner private Point topRight; // upper right corner private Point bottomLeft; // lower left corner private Point bottomRight; // lower right corner /** * The constructor sets initial values for the Points. * @param topL The upper left Point. * @param topR The upper right Point. * @param botL The lower left Point. * @param botR The lower right Point. */ public Rectangle(Point topL, Point topR, Point botL, Point botR) { topLeft = topL; topRight = topR; bottomLeft = botL; bottomRight = botR; } /** * A second constructor makes this object share Points * with the one passed as a parameter. * @param otherRect The rectangle to copy. */ public Rectangle(Rectangle otherRect) { this(otherRect.topLeft, otherRect.topRight, otherRect.bottomLeft, otherRect.bottomRight); } /** * Accessor for the top left Point. * @return The upper left corner. */ public Point getTopLeft() { return topLeft; } /** * Calculates the width of this Rectangle by calling * some methods of its Point data members. * @return The width. */ public int getWidth() { return (topRight.getX() - topLeft.getX()); } /** * Calculates the height of this Rectangle by calling * some methods of its Point data members. * @return The height. */ public int getHeight() { return (bottomLeft.getY() – topLeft.getY()); } /** * Calculates the area of this Rectangle by calling * some other methods in this class. * @return The area. */ public int getArea() { return (getWidth() * getHeight()); } }