Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Repository;
- import Model.Animals;
- public class Repo {
- private Animals[] a_list;
- private int position = 0;
- public Repo(int length){ this.a_list = new Animals[length];}
- public void add(Animals a) throws MyException {
- if (this.a_list.length <= position)
- {
- throw new MyException("Repository has reached maximum capacity");
- }
- else
- {
- this.a_list[position] = a;
- position++;
- }
- }
- public void delete(int poz) throws MyException{
- if (poz < 0 || poz > this.a_list.length)
- {
- throw new MyException("The position you provided is invalid");
- }
- else
- {
- for (int i = poz; i < this.a_list.length - 1 ; i++)
- a_list[i] = a_list[i+1];
- this.position--;
- }
- }
- public Animals[] getBig(){
- Animals[] b_list = new Animals[this.a_list.length];
- int poz = 0;
- for (Animals a : this.a_list) {
- if (a.check_Weight()) {
- b_list[poz] = a;
- ++poz;
- }
- }
- return b_list;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement