It can be as simple as this:
class Female implements Comparable<Female> {
// ...
public int compareTo(Female that) {
return this.age - that.age;
}
}
Because all you have to return is:
a negative integer, zero, or a positive integer as this object is less
than, equal to, or greater than the specified object.
http://docs.oracle.com/javase/7/docs/api/java/lang/Comparable.html
Be aware that this implementation comes with risks. This assumes that subtracting ages will not cause an overflow which could happen if their signs differ (essentially making this addition) and the sum of their magnitude was greater than age's type can hold.
Another important point to note is don't use subtraction for comparing
integral values because result of subtraction can overflow as every
int operation in Java is modulo 2^32. use either Integer.compareTo()
or logical operators for comparison. There is one scenario where you
can use subtraction to reduce clutter and improve performance. As we
know compareTo doesn't care magnitude, it just care whether result is
positive or negative. While comparing two integral fields you can use
subtraction if you are absolutely sure that both operands are positive
integer or more precisely [their difference] must be less than
Integer.MAX_VALUE. In this case there will be no overflow and your
compareTo will be concise and faster.
http://javarevisited.blogspot.com/2011/11/how-to-override-compareto-method-in.html