//******************************************************************** // BookList.java Author: Lewis and Loftus // // Represents a collection of books. //******************************************************************* import Book; public class BookList { private BookNode list; //---------------------------------------------------------------- // Sets up an initially empty list of books. //---------------------------------------------------------------- BookList() { list = null; } //---------------------------------------------------------------- // Creates a new Book object and adds it to the end of // the linked list. //---------------------------------------------------------------- public void add (Book newBook) { BookNode node = new BookNode (newBook); BookNode current; if (list == null) list = node; else { current = list; while (current.next != null) current = current.next; current.next = node; } } //---------------------------------------------------------------- // Returns this list of books as a string. //---------------------------------------------------------------- public String toString () { String result = ""; BookNode current = list; while (current != null) { result += current.book.toString() + "\n"; current = current.next; } return result; } //***************************************************************** // An inner class that represents a node in the book list. The // public variables are accessed by the BookList class. //***************************************************************** private class BookNode { public Book book; public BookNode next; //-------------------------------------------------------------- // Sets up the node //-------------------------------------------------------------- public BookNode (Book theBook) { book = theBook; next = null; } } }