Advertisement
Guest User

Untitled

a guest
Feb 28th, 2017
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.77 KB | None | 0 0
  1.     // Aforementioned method to return available animals.
  2.     public int getAvailableAnimals() {
  3.         return totalAnimals - loanedAnimals;
  4.     }
  5.  
  6.     // Checks if the number of available animals is greater than 1, or an exception is thrown as its impossible to return
  7.     // an animal if none are available.
  8.     public void loanAnimal() {
  9.  
  10.         if (getAvailableAnimals() < 1) {
  11.             throw new IllegalStateException("No Animals Available to Loan.");
  12.         }
  13.  
  14.         loanedAnimals++;
  15.     }
  16.  
  17.  
  18.     // Checks if the number of loaned animals is greater than 1, or an exception is thrown as its impossible to return
  19.     // an animal if none are on loan.
  20.     public void returnAnimal() {
  21.  
  22.         if (this.loanedAnimals < 1) {
  23.             throw new IllegalStateException("No Animals are on Loan.");
  24.         }
  25.  
  26.         loanedAnimals--;
  27.     }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement