What is a Comparable interface? It is an interface containing single method:
compareTo(T o)
providing capability for Java to comprare your object with any other. Basically you would like to compare your object with those of the same kind (class). So there is a usual check in compareTo implementation:
if (o instanceof vehicles) {
Vehicles v = (Vehicles)o;
// compare
} else {
return false;
}
Then, in compare section you should decide, based on your business-rules, whether other vehicle is equals, more of less to your object.
- 0 - if they are equal;
- 1 - if your object is greater;
- -1 - if your object is lesser.
All that simple!