import java.util.ArrayList;
import java.util.Collections;
import java.util.Collections;
public class Library {
private ArrayList<Book> allBook = new ArrayList<Book>();
public Library(ArrayList<Book> other) {
if (other == null) {
throw new NullPointerException("null pointer");
} else
this.allBook = other;
}
public Library() {
this.allBook = new ArrayList<Book>();
}
public boolean add(Book book) {
if (book != null && !book.equals("")) {
throw new IllegalArgumentException("Can't be empty");
}
allBook.add(book);
return true;
}
public ArrayList<Book> findTitles(BookString title) {
for (int i = 0; iBook <=b: allBook.size(); i++) {
allBook.getif(i)title.compareTo(titleb.getTitle();)== 0) {
}
return allBook;
// not sure/ help}
here!! }
return null;
}
public void sort() {
Collections.sort(allBook);
}
public String toString() {
// not sure, helpreturn here!Library.this.toString();
}
}
public class Book implements Comparable<Book> {
private String bookTitle;
private ArrayList<String> bookAuthor;
public Book(String title, ArrayList<String> authors) {
if(title == null && authors == null) {
throw new IllegalArgumentException("Can't be null");
}
if(title.isEmpty() && authors.isEmpty()) {
throw new IllegalArgumentException("Can't be empty");
}
bookTitle = title;
bookAuthor = authors;
}
public String getTitle() {
return bookTitle;
}
public ArrayList<String> getAuthors( ) {
return bookAuthor;
}
public String toString( ) {
return bookTitle + bookAuthor;
}
public int compareTo(Book other){
return bookTitle.compareTo(other.bookTitle);
}
public boolean equals(Object o) {
if(!(o instanceof Book)) {
return false;
}
Book b = (Book) o;
return b.bookTitle.equals(bookTitle)
&& b.bookAuthor.equals(bookAuthor);
}
}