Create a class called Car
that implements the OurComparable
interface.
Car
should provide a primary 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 property.
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: fun compareTo(o: Any): Int
.
You're challenge is to write tests for this problem described above.
Stuck? You may find these lessons helpful: