// Class to represent a rectangle public class Rectangle implements Shape { private double length; private double width; public Rectangle(double length, double width) { this.length = length; this.width = width; } // returns the area of this rectangle public double area() { return length * width; } // compares this rectangle to other by area // pre: other != null public int compareTo(Shape other) { if (this.area() < other.area()) { return -1; } else if (this.area() > other.area()) { return 1; } else { return 0; } } public String toString() { return "rectangle of area " + String.format("%.3f", area()); } }