Reference no: EM131560
Each instance of this class will represent one book. A book consists of the title of the book, a String, and the author(s). Since books can have an arbitrary number of authors, you are to use an ArrayList of String to hold the authors.
The title of the book is passed to the constructor (see below). The author(s) of the book may, or may not, be supplied when the instance is created. Authors can be added to the book. The authors should be kept in the order in which they were added (not necessarily alphabetical). Authors usually agree on the order of their names for the book, and we will maintain them in that order.
Constructors:
• A constructor that takes a single argument, a String, that is the title of the book.
• A second constructor that takes two arguments: a String that is the title of the book and an ArrayList of String that contains the authors.
Methods:
• set and get methods for the title. The get method for the title returns a String.
• get method for the authors that returns an ArrayList containing String's.
• addAuthor: will take a String and return a void. This author is added to the end of the current list of authors for the book. The method should verify that the author is not already in the list of authors. If the author is already present in the list of authors, then the method simply returns. Each author of a book should appear exactly once.
• toString: will return a String that has the title of the book, followed on separate lines by each of the authors. The title is preceded by the phrase "Title: " - note there is one space after the colon. Each author name is indented three spaces.
• equals: Takes an Object. The object will be a String, but is declared as an Object. The method will test whether the argument is, or is not, the same as the title of the book. Note: the authors are not part of this comparison.
• compareTo: Takes a Title argument. Returns the result of the compareTo method of String applied to the titles (not the authors).
Methods:
• addTitle: will take a String and return a boolean. If the title is already present in the list of books, return false. If the title is not present in the list of books, then add the title to the list in alphabetical order.
• findTitle: will take a String and return a Title. If the title is not present in the list of books, return null. If the Title is present in the list of books, then return a reference to the Title.
• remove: will take a String and return a boolean. If the title is present in the list of books, then remove the title and return true. If the title is not present in the list of books, then return false.
• toString: will return a String containing all the titles and authors. The titles should be in alphabetical order. The authors for each book will be in the order speci?ed when the authors were added to the title.
• toStringTitles: will return a String containing all the titles, one title to a line. The titles should be in alphabetical order. No authors will appear in this String.