Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2017
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.18 KB | None | 0 0
  1. package Repository;
  2.  
  3. import Model.Animals;
  4.  
  5. public class Repo {
  6.     private Animals[] a_list;
  7.     private int position = 0;
  8.  
  9.     public Repo(int length){ this.a_list = new Animals[length];}
  10.     public void add(Animals a) throws MyException {
  11.         if (this.a_list.length <= position)
  12.         {
  13.             throw new MyException("Repository has reached maximum capacity");
  14.         }
  15.         else
  16.         {
  17.             this.a_list[position] = a;
  18.             position++;
  19.  
  20.         }
  21.     }
  22.     public void delete(int poz) throws MyException{
  23.         if (poz < 0 || poz > this.a_list.length)
  24.         {
  25.             throw new MyException("The position you provided is invalid");
  26.         }
  27.         else
  28.         {
  29.             for (int i = poz; i < this.a_list.length - 1 ; i++)
  30.                 a_list[i] = a_list[i+1];
  31.             this.position--;
  32.  
  33.         }
  34.     }
  35.     public Animals[] getBig(){
  36.          Animals[] b_list = new Animals[this.a_list.length];
  37.          int poz = 0;
  38.          for (Animals a : this.a_list) {
  39.              if (a.check_Weight()) {
  40.                  b_list[poz] = a;
  41.                  ++poz;
  42.              }
  43.  
  44.          }
  45.          return b_list;
  46.     }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement