Comparable BiggerSmaller Counter
Complete the implementation of a public class named BiggerSmallerCounter
.
Provide a public constructor that accepts a single parameter, any Java object that implements Comparable
.
The parameter passed will not be null
.
This sets the initial threshold.
BiggerSmallerCounter
should also provide the following instance methods:
add
: takes a reference to any Java object that implementsComparable
bigger
: retrieves the count (as anint
) of the number of values passed toadd
that were bigger than the threshold set when the object was createdsmaller
: retrieves the count (as anint
) of the number of values added toadd
that were smaller than the threshold set when the object was created
You should compare Comparable
objects using compareTo
.
(You do not need to handle specially the case where different Comparable
classes cannot be compared to each other.)
As a reminder, first.compareTo(second)
returns a positive value if first
is larger than second
, a negative
value if first
is smaller than second
, and 0 if they are equal.
When you are done your BiggerSmallerCounter
class should work as follows:
Note that null
will not be passed as an argument to add
.
You should not use an array to solve this problem. You will lose credit for doing so.