public class ComparableCircles implements Comparable // example of a Circle that implements Comparable { private int x, y, r; // center (x,y) and radius public ComparableCircles() // no arg constructor, initialize all to 0 { x=y=r=0; } public ComparableCircles(int x, int y, int r) // normal constructor { this.x=x; this.y=y; this.r=r; } //accessors public int getX() {return x;} public int getY() {return y;} public int getRadius() {return r;} // toString describes the circle public String toString() { return "This circle has a center point at " + x + "," + y + " and has a radius of " + r; } // implement Comparable here @Override public int compareTo(Object o) // receive an Object and put it in a variable of type ComparableCircles so that we don't have { // to do further casting ComparableCircles other=(ComparableCircles)o; return r-other.getRadius(); // compareTo just compares radii, if this Circle's r > other's r, return +number, if < return -number, } // returns 0 if the two radii are the same public boolean equals(Object o) // this method returns true only if the two circles have the same x,y coordinates and radius { ComparableCircles other=(ComparableCircles)o; // again, place o into a ComparableCircle to prevent need for further casting if(x==other.getX()&&y==other.getY()&&r==other.getRadius()) return true; // true only if the two Circles are the same else return false; } }