Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

need to creat a book catalog using a menu that looks like this 1. Search Catalog

ID: 3815082 • Letter: N

Question

need to creat a book catalog using a menu that looks like this

1. Search Catalog

2. Check out

3. Return

4. Add a new item

5. Exit

right now i have this program and there is a couple issues with it like how im getting an error with everything wih the gets function. if you could recreat this program or edit it to not have any gets function that would be great and do not use infile and use this list of books instead inside of the program i am using visual studio.

the books to be used shoudl be:the great gadsby,to kill a mockingbird,soulmates,pablo,makerschoice.

magazines to be used:spiderman,time,batman,daredevile,luke cage.

journals:journal of biology,advanced materials,cell,nature,microbiology

Explanation / Answer

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(String title) {
for(Book b: allBook) {
if(title.compareTo(b.getTitle())== 0) {
return allBook;
}
}
return null;
}
public void sort() {
Collections.sort(allBook);
}

public String toString() {
return 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);
}
}