-1

私はこれを何年も見てきましたが、listOfBooks が見つからない理由がわかりません。で間違って定義しましたpublic class Libraryか? コードは次のとおりです。

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");
            }
        }
    }
}

誰が私が間違っているのか教えてもらえますか?

4

1 に答える 1