Advertisement
Guest User

Untitled

a guest
Jan 16th, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.34 KB | None | 0 0
  1. int lengthNew = other.library.length + this.library.length;
  2.         Book[] newLibrary = new Book[lengthNew];
  3.         int otherCounter = 0, thisCounter = 0;
  4.  
  5.         while(otherCounter < other.library.length || thisCounter < this.library.length){
  6.             if(otherCounter == other.library.length){
  7.                 newLibrary[thisCounter + otherCounter] = this.library[thisCounter];
  8.                 thisCounter++;
  9.             }else if(thisCounter == this.library.length){
  10.                 newLibrary[thisCounter + otherCounter] = other.library[otherCounter];
  11.                 otherCounter++;
  12.             }else if(other.library[otherCounter].getIsbn() < this.library[thisCounter].getIsbn()){
  13.                 newLibrary[thisCounter + otherCounter] = other.library[otherCounter];
  14.                 otherCounter++;
  15.                 System.out.println("Added - other");
  16.             }else if(this.library[thisCounter].getIsbn() < other.library[otherCounter].getIsbn()){
  17.                 newLibrary[thisCounter + otherCounter] = this.library[thisCounter];
  18.                 thisCounter++;
  19.                 System.out.println("Added - this");
  20.             }else if(this.library[thisCounter].getIsbn() == other.library[otherCounter].getIsbn()){
  21.                 newLibrary[thisCounter + otherCounter] = this.library[thisCounter];
  22.                 newLibrary[thisCounter + otherCounter + 1] = this.library[thisCounter];
  23.                 System.out.println("Added - both");
  24.                 thisCounter++;
  25.                 otherCounter++;
  26.             }  
  27.         }
  28.         Library newLib = new Library(newLibrary);
  29.         return newLib;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement