Create a class called Car
that implements the OurComparable
interface.
Car
should provide a public constructor that takes a single int
argument that sets that car's odometer.
You should assert that the provided int
is not negative.
Do not expose the odometer variable.
You should order cars based on their odometer reading, from least to greatest.
Specifically, compareTo
should return:
If the passed value is not a Car
, throw an IllegalArgumentException
.
As a reminder, the OurComparable
interface comprises a single method: int compareTo(Object other)
.
Stuck? You may find these lessons helpful: