/* Rectangle.java */
public class Rectangle implements Comparable<Rectangle>{
    protected int l;
    protected int w;

    // three constructors
    // setters and getters
    // method to calculate area
    // method to print l and w
    public Rectangle() {
    }
    public Rectangle(int l) {
        this.l = l;
    }
    public Rectangle(int l, int w) {
        this.l = l;
        this.w = w;
    }
    public Integer area(){
        return l * w;
    }

    public Integer volume(){
        return 0;
    }

    public void print(){
        System.out.println("length = " + l + "; width = " + w);
    }

    @Override
    public int compareTo(Rectangle other) {
        // Compare based on area or volume
        if (this.volume() == 0 && other.volume() == 0) {
            return this.area().compareTo(other.area());
        }
        else {
            return this.volume().compareTo(other.volume());
        }
    }
}


/* Box.java */
public class Box extends Rectangle{
    private int h;

    //four constructors
    //setters and getters
    //method to calculate volume
    //override print method
    public Box(){
        super();
    }
    public Box(int l){
        super(l);
    }
    public Box(int l, int w){
        super(l ,w);
    }
    public Box(int l, int w, int h){
        super(l ,w);
        this.h = h;
    }

    @Override
    public Integer volume(){
        return area() * h;
    }

    @Override
    public void print() {
        System.out.println("length = " + l + "; width = " + w + "; height = " + h);
    }

}


/* Main.java */
public class Main {

    public static void showVol(Rectangle r) {
        //System.out.println(r.volume());
    }

    public static void main(String[] args) {
	    // make an array of 100 rectangles of random size
        // find the one of biggest volume
        // ...

        // test Box and Rectangle, see if comparable
        Box a = new Box(1, 2, 3);
        Box b = new Box(2, 3, 4);
        if (a.compareTo(b) < 0) {
            System.out.println("Box a is smaller than Box b");
        }

        Rectangle c = new Rectangle(1, 2);
        Rectangle d = new Rectangle(3, 4);
        if (c.compareTo(d) < 0) {
            System.out.println("Rectangle c is smaller than Rectangle d");
        }

    }
}
