Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Aforementioned method to return available animals.
- public int getAvailableAnimals() {
- return totalAnimals - loanedAnimals;
- }
- // Checks if the number of available animals is greater than 1, or an exception is thrown as its impossible to return
- // an animal if none are available.
- public void loanAnimal() {
- if (getAvailableAnimals() < 1) {
- throw new IllegalStateException("No Animals Available to Loan.");
- }
- loanedAnimals++;
- }
- // Checks if the number of loaned animals is greater than 1, or an exception is thrown as its impossible to return
- // an animal if none are on loan.
- public void returnAnimal() {
- if (this.loanedAnimals < 1) {
- throw new IllegalStateException("No Animals are on Loan.");
- }
- loanedAnimals--;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement