I've been looking at this for ages and I cannot figure out why it cannot find listOfBooks. Have I defined it incorrectly in my public class Library
?
Here's the code:
Library.java
import java.util.List;
import java.util.ArrayList;
public class Library {
private List<Book> listOfBooks;
private int capacity;
private boolean libLimited;
public Library() {
libLimited = false;
}
public Library(int inCapacity) {
libLimited = true;
capacity = inCapacity;
}
public void addBook(Book newBook) {
if (newBook != null && !newBook.equals("")) {
throw new IllegalArgumentException("Can't be empty");
}
listOfBooks.add(newBook);
}
public String numberAvailableBooks() {
boolean newBookPresent = false;
for (Book newBook : listOfBooks) {
if (!newBook.isBorrowed()) {
return (newBook.getTitle());
newBookPresent = true;
}
}
}
public int hasBookWithTitle(String bookTitle) {
for (Book book : listOfBooks) {
if (bookTitle.equalsIgnoreCase(listOfBooks.getTitle()) == true) {
return true;
}
}
return false;
}
public String getBookWithTitle(String bookTitle) {
for (Book book : listOfBooks) {
if (bookTitle.equlsIgnoreCase(listOfBooks.getTitle()) == true) {
return listOfBooks;
}
}
return null;
}
}
Book.java
public class Book {
private String title;
private String author;
private int copies;
private boolean borrowed;
public Book(String inAuthor, String inTitle, int inNumberOfCopies) {
this.author = inAuthor;
this.title = inAuthor;
this.copies = inNumberOfCopies;
}
public void borrowed() {
borrowed = true;
}
public void rented() {
borrowed = true;
}
public void returned() {
borrowed = false;
}
public boolean isBorrowed() {
return borrowed;
}
public String getAuthor() {
return this.author;
}
public String getTitle() {
return this.title;
}
public int getTotalCopies() {
return this.copies;
}
public int getAvailableCopies() {
}
public void withdrawCopy() {
int found = 0;
for (Book b : listOfBooks) {
if (b.getTitle().equals(title)) {
if (found == 0) {
found = 1;
}
if (!b.isBorrowed()) ;
{
b.borrowed = true;
found = 2;
break;
throw new IllegalStateException("Nothing to Withdraw");
}
}
}
}
public String returnCopy() {
boolean found = false;
for (Book book : listOfBooks) {
if (book.getTitle().equals(title) && book.isBorrowed()) {
book.returned();
found = true;
break;
throw new IllegalStateException("Cannot Return");
}
}
}
}
Can anyone tell me what I'm doing wrong?