public class Rectangle implements MyComparable{ // the Rectangle class has 3 fields private int width; private int height; private Point origin; // the Rectangle class has one constructor public Rectangle(int initWidth, int initHeight, Point initOrigin) { width = initWidth; height = initHeight; origin = initOrigin; } public Rectangle(int initWidth, int initHeight, int xPos, int yPos) { this(initWidth, initHeight, new Point(xPos,yPos)); } public Rectangle(int initWidth, int initHeight) { this(initWidth, initHeight, 0, 0); } public void setWidth(int newWidth ) { width = newWidth; } public int getWidth() { return width; } public void setHeight(int newHeight ) { height = newHeight; } public int getHeight() { return height; } public void setOrigin(Point newOrigin) { origin = newOrigin; } public Point getOrigin() { return origin; } @Override public boolean isLarger(MyComparable other) throws InvalidComparableTypeException { if( other instanceof Rectangle ) { Rectangle otherRect = (Rectangle) other; return (this.getArea() > otherRect.getArea()); } throw new InvalidComparableTypeException(); } @Override public boolean isEqual(MyComparable other) throws InvalidComparableTypeException { if( other instanceof Rectangle ) { Rectangle otherRect = (Rectangle) other; return (this.getArea() == otherRect.getArea()); } throw new InvalidComparableTypeException(); } @Override public String toString() { return origin.toString() + ", " + width + " X " + height ; } public double getArea() { return (double)width * height; } }