Comparable Cat
Create a class called Cat
that implements the Comparable
interface.
Cat
should provide a public constructor that takes a single double
argument that sets that cat's age.
You should assert that the provided age is not negative.
You should order cats based on their age.
Specifically, compareTo
should return:
- -1 if this cat is younger than the passed cat
- 0 if this cat is the same age as the passed cat, or if the passed value is not a
Cat
- 1 if this cat is older than the passed cat
As a reminder, the Comparable
interface comprises a single method: int compareTo(Object other)
.