title: return the first Book object written by an author with this first name in Array?
body: <p>Hi sorry beginner coder here and I am not good at explaining things very well but I was wondering  how do I return the first book object of an Array?</p>
  
  <p>Here is my code: </p>
  
  <pre><code>public Book getBookWrittenBy(String firstName){
      Book writtenBy = null;
  
      if((inventory == null) || (inventory.length == 0)){
          return null;
      }
      for(int i=0; i &lt; inventory.length; i++){
          if(inventory[i] != null &amp;&amp; writtenBy == null || inventory[i].getTitle().equals(firstName)){
              writtenBy = inventory[i];
          }
  
      }
      return writtenBy;
  }
  </code></pre>
  
  <p>When I test this code on BlueJ compiler it returns a title from the Author but not the First instance of the <code>Book</code> object with the <code>firstName</code>.</p>
  
  <p>Here is the method I need to use:</p>
  
  <p><code>public Book getBookWrittenBy(String firstName)</code></p>
  
  <ul>
  <li>returns the first <code>Book</code> object written by an author with this first name</li>
  </ul>
  
  <p>If any one can help me code this that would be greatly appreciated.  Many thanks in advance. </p>