OurComparable Car
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:
- -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: int compareTo(Object other)
.