Define a class named Min
which stores the minimum from a series of provided Int
values.
Min
should define a primary constructor that accepts a Int
that sets the initial value.
You should also provide two other instance methods:
add
: accepts a single Int
and updates the minimum if necessary, but does not return a valuemin
: returns the current minimum valueOnce your class works correctly it should behave like this:
Your Min
class should not expose any state publicly.
You may also not store passed values in an array.
This is incorrect and will prevent your class from recording the maximum of a large number of values!
You're challenge is to write tests for this problem described above.
Stuck? You may find these lessons helpful: