/** A Rectangle using the Class Point */ public class Rectangle { private Point leftUpperCorner; private Point rightLowerCorner; /** Constructor */ public Rectangle(double x, double y, double width, double heigth) { leftUpperCorner = new Point(x,y); rightLowerCorner = new Point(x+width,y-heigth); } /** Constructor */ public Rectangle(Point leftUpperCorner, Point rightLowerCorner) { this.leftUpperCorner = new Point(leftUpperCorner); this.rightLowerCorner = new Point(rightLowerCorner); } /** Default constructor */ public Rectangle() { leftUpperCorner = new Point(); rightLowerCorner = new Point(); } /** Returns the width of the rectangle */ public double width() { return (rightLowerCorner.x-leftUpperCorner.x); } /** Returns the height of the rectangle */ public double heigth() { return (leftUpperCorner.y-rightLowerCorner.y); } /** Returns the position of the left upper corner as a Point */ public Point position() { return leftUpperCorner; } /** Calculates the area */ public double area() { return (width()*heigth()); } /** Calculates the perimeter */ public double perimeter() { return (2*(width()+heigth())); } /** Prints the position, width and heigth on STDOUT */ public String toString() { return ("Rectangle at " + position() + " with width="+width() + " and heigth="+heigth()); } }