A class implements the Comparable
interface when there is a way to
decide whether one object of the class is greater than another. The
compareTo
method is the way to find out how the two classes
compare.
Exercises from 2018.
Example implementing Comparable for a clock class with hours and minutes.
A Bug can go one of four directions: “North”, “South”, “East”, and “West”. A bug also has a speed, which is a non-negative integer. Bugs are going to be ordered using both their direction and speed. The “primary” method of ordering bugs will be their direction. We will consider their speed only if their directions are the same. Direction: West < South < East < North Speed: small number < big number You are going to write the code, including a constructor Bug (String direction, int speed).