title: Java Arrays, Instantiation and sorting
body: <p>I am completing a homework problem for a Java course that has to do with instantiation, arrays and sorting of array data. Here is the question:</p>
  
  <blockquote>
    <p>Create a class named <code>LibraryBook</code> that contains fields to hold
    methods for setting and getting a <code>LibraryBook</code>'s title, author, and
    page count. Save the file as LibraryBook.java.</p>
    
    <p>Write an application that instantiates five <code>LibraryBook</code> objects and
    prompts the user for values for the data fields. Then prompt the user
    to enter which field the <code>LibraryBooks</code> should be sorted by - title,
    author, or page count. Perform the requested sort procedure and
    display the <code>LibraryBook</code> objects. Save the file as
    LibraryBookSort.java.</p>
  </blockquote>
  
  <p>The professor also added the following criteria in addition to the book:</p>
  
  <blockquote>
    <p>Declare an array of <code>LibraryBook</code> objects and sort them either by
    title, author or page count, as the user requests.</p>
  </blockquote>
  
  <p>Here is the code I have for LibraryBook.java:</p>
  
  <pre><code>public class LibraryBook
  {
          String bookTitle;
          String bookAuthor;
          int bookPageCount;
  
          public LibraryBook(String title, String author, int count)
          {
              bookTitle = title;
              bookAuthor = author;
              bookPageCount = count;
          }
  
          public String getBookTitle()
          {
              return bookTitle;
          }
  
          public String getBookAuthor()
          {
              return bookAuthor;
          }
  
          public int getBookPageCount()
          {
              return bookPageCount;
          }
  }
  </code></pre>
  
  <p>Here is the code I have so far for LibraryBookSort.java:</p>
  
  <pre><code>import java.util.Arrays;
  import java.util.Scanner;
  
  public class LibraryBookSort
  {
      public static void main(String[] args)
      {
  
      LibraryBook[] book = new LibraryBook[5];
  
      book[0] = new LibraryBook("Java Programming", "Joyce Farrell", 881);
      book[1] = new LibraryBook("Team Of Rivals", "Dorris Kearns Goodwin", 994);
      book[2] = new LibraryBook("1776", "Daivd McCullough", 400);
      book[3] = new LibraryBook("No Ordinary Time", "Dorris Kearns Goodwin", 768);
      book[4] = new LibraryBook("Steve Jobs", "Walter Isaacson", 656);
  
      for (int x = 0; x &lt; book.length; ++x)
          book[x].getBookTitle();
      for (int x = 0; x &lt; book.length; ++x)
          System.out.println(book[x].getBookTitle());
  
      for (int x = 0; x &lt; book.length; ++x)
          book[x].getBookAuthor();
      for (int x = 0; x &lt; book.length; ++x)
          System.out.println(book[x].getBookAuthor());
  
      for (int x = 0; x &lt; book.length; ++x)
          book[x].getBookPageCount();
      for (int x = 0; x &lt; book.length; ++x)
          System.out.println(book[x].getBookPageCount());
      }
  }
  </code></pre>
  
  <p>The code above seems to work and displays all of the data, although not formatted correctly. I want the data to look like the following:</p>
  
  <pre><code>Java Programming       Joyce Farrel               881
  Team Of Rivals         Dorris Kearns Goodwin      994
  1776                   Daivd McCullough           400  
  No Ordinary Time       Dorris Kearns Goodwin      768
  Steve Jobs             Walter Isaacson            656
  </code></pre>
  
  <p>In addition to the output being formatted like the above, I need to have each of the data types (Title, Author, Pages) sortable by the users selection.</p>
  
  <p>At this point, I am just lost. This is above my skill level thus far. I am hoping that someone could give me some pointers/direction on where to go at this point.</p>