Restaurant Capacity Manager
Create a class CapacityManager
to manage restaurant dining capacity.
You should provide a primary constructor that allows the capacity of the restaurant to be set as an Int
when the
CapacityManager
is created.
You don't need to provide either a getter or a setter for the capacity, which will not change.
Provide two methods: enter
and leave
.
Each accepts a count of guests (as an Int
) that are either arriving (enter
) or departing (leave
) from the
restaurant.
Both should return the number of guests after the operation completes as an Int
.
If the count is negative or zero, both methods should throw an IllegalArgumentException
.
enter
should also throw a IllegalStateException
if the new party would exceed the capacity of the restaurant.
This restaurant also refuses to admit parties larger than 8, and if one arrives enter
should throw a
PartyTooLarge
exception, which you can create without importing:
leave
should also throw an IllegalStateException
if a party leaves that is larger than 8, or if the leave
would cause the number of diners to fall below zero, since both represent mistakes in our enter
code.
In both enter
and leave
, if an exception is thrown, the number of diners should not be changed.
When you are finished, here is how your class should work:
Do not use assert
to solve this problem!
However, you can still use require
and check
to generate some (but not all) of the exceptions mentioned above.