OurComparable Car
Geoffrey Challen // 2023.10.0
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:
- -1 if this car has a lower odometer reading than the passed car
- 0 if this car has the same odometer reading as the passed car
- 1 if this car has a higher odometer reading than the passed car
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
.