title: Library system - Borrowing a book
body: <p>I've been working on a library system for a few weeks now, but have a problem whilst trying to initialize the &quot;borrow&quot; feature for the system. I would really appreciate if someone could help me out. Here is the code I have so far for the &quot;borrow&quot; feature.</p>
  <p><strong>Library class - includes faulty borrow</strong></p>
  <p>private List collection;</p>
  <pre><code>public Library()
  {
      collection = new ArrayList&lt;Book&gt;();
  }
  
  public void addBook(Book book)
  {
      collection.add(book);
  }
  
  public String searchTitle(String titleSearch) {
      if (titleSearch == null) return &quot;\n No Books Avaliable &quot;;
      for(int i = 0; i &lt; collection.size(); i++){
          if(titleSearch.equalsIgnoreCase(collection.get(i).getTitle())){
              return collection.get(i).toString();
          }
      }
      return &quot;\n No Books Avaliable &quot;; //reachable only if no book found
  }
  
  public String toString()
  {
      String total = &quot;\n &quot;;
      for (int i=0; i&lt;collection.size(); i++)
      {
          Book b = collection.get(i);
          total = total + b.toString();
      }
  
      return total;
  }
      public void borrowBook(String title) {
      int found = 0;
      for (Book b : collection) {
          if (collection.getTitle().equals(title)) {
              if (found == 0) {
                  found = 1;
                  }
              if (!book.isBorrowed()) {
                  book.borrowed();
                  found = 2;
                  break;
              };
          }
      }
      if (found == 0) {
          System.out.println(&quot;Sorry, this book is not in our catalog.&quot;);
      } else if (found == 1) {
          System.out.println(&quot;Sorry, this book is already borrowed.&quot;);
      } else if (found == 2) {
          System.out.println(&quot;You successfully borrowed &quot; + title);
      }
  }
  </code></pre>
  <p>}</p>
  <p><strong>This is the Book class</strong></p>
  <pre><code>public Book(int isbn, String author, String title, String genre, int  
   numcopies)
  {
  
      this.isbn = isbn;
      this.author = author;
      this.title = title;
      this.genre = genre;
      this.numcopies = numcopies;
  
  
  }
  
  public int getISBN()
  {
      return isbn;
  }
  public String getAuthor()
  {
      return author;
  }
  public String getTitle()
  {
      return title;
  }
  public String getGenre()
  {
      return genre;
  }
  public String toString()
  {
      return &quot;\nISBN: &quot; +isbn + &quot;\nAuthor: &quot; +author + &quot;\nTitle: &quot; +title + 
    &quot;\nGenre: &quot; +genre + &quot;\nNumber Of Copies &quot; +numcopies +&quot;\n &quot;;
  }
  </code></pre>
  <p>}</p>