abstract class shape implements Comparable { int x, y; double distance(shape other) { int dx = x-other.x, dy = y-other.y; return Math.sqrt(dx*dx + dy*dy); } public int compareTo(shape other) { int a = (int)(area()*1000+0.5); int b = (int)(area()*1000+0.5); return a-b; } abstract double area(); abstract double circumference(); }//shape class circle extends shape { double radius; circle(int a, int b, int r) {x=a;y=b;radius=r;} double area() {return Math.PI*radius*radius;} double circumference() {return Math.PI*radius*2;} }//circle class rectangle extends shape { double width, height; rectangle(int a, int b, double w, double h) { x=a; y=b; width=w; height=h; } double area() { return width*height; } double circumference() { return width*2 + height*2; } }//rectangle // ... triangle, etc public class shapes2 { public static void main(String[] args) { shape S[] = new shape[4]; S[0] = new circle(3,4,5); S[1] = new circle(50,60,10); S[2] = new rectangle(3,4,5,6); S[3] = new rectangle(30,40,50,60); double totalarea = 0; for(var c:S) totalarea+=c.area(); System.out.printf("totalarea = %.2f\n",totalarea); }//main }