public class GeometricObjectDemo { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub Circle cake1 = new Circle(2); Square cake2 = new Square(3.5); System.out.println(cake1.getArea()); System.out.println(cake2.getArea()); System.out.println(cake1.compareTo(cake2)); } } abstract class GeometricObject implements Comparable{ String name; Date dateCreated; abstract double getArea(); public int compareTo(Object other){ double thisArea = this.getArea(); double otherArea = ((GeometricObject) other).getArea(); if(thisArea < otherArea){ return -1; } if(thisArea > otherArea){ return 1; } return 0; } } class Circle extends GeometricObject{ double radius; Circle(double rad){ radius = rad; } double getArea(){ return radius*radius*Math.PI; } } class Square extends GeometricObject{ double side; Square(double s){ side = s; } double getArea(){ return side*side; } }