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:
Each accepts a count of guests (as an
Int) that are either arriving (
enter) or departing (
leave) from the
Both should return the number of guests after the operation completes as an
If the count is negative or zero, both methods should throw an
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
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
check to generate some (but not all) of the exceptions mentioned above.