Facebook
From Cute Hedgehog, 3 Years ago, written in Java.
Embed
Download Paste or View Raw
Hits: 114
  1. public boolean add(String title, String author)
  2.   {
  3.     LibraryBook add;
  4.     LibraryBook temp;
  5.     add = new LibraryBook(title, author);
  6.     bookList.add(add);
  7.     if(bookList.size() > 1)
  8.       System.out.println("The book with title \"" + title + "\" has been added to the library.");
  9.     {
  10.       for(int i = 0; bookList.size() > i; i++)
  11.       {
  12.         for(int j = i + 1; bookList.size() > j; j++) //checking whether the next books are followed by the book and updating it.
  13.         {
  14.           if(bookList.get(i).getAuthor().compareTo(bookList.get(j).getAuthor()) > 0 ||
  15.              (bookList.get(i).getAuthor().equals(bookList.get(j).getAuthor()) &&
  16.               bookList.get(i).getTitle().compareTo(bookList.get(j).getTitle()) > 0 ))
  17.           {
  18.             temp = bookList.get(i);
  19.             bookList.set(i, bookList.get(j));
  20.             bookList.set(j, temp);
  21.           }
  22.         }
  23.       }
  24.     }
  25.     return true;
  26.   }