返回我的图书馆系统的问题

issue with returning on my library system

我已将 return 功能添加到我的图书馆系统,该功能运行良好。问题是,return读完一本书再去拿,不成功,提示"the book is already borrowed"。我正在努力解决这个问题。

这是我的系统 'borrowing book' 和 'return book' 的代码...

public String borrowBook(String titleBorrow) 
{
    int found = 0;
    String bookFound = "\n";
    for (Book b : collection) 
    {
        if (b.getTitle().equals(titleBorrow)) 
        {
            if (found == 0) 
            {
                found = 1;
            }
            if (!b.isBorrowed()) 
            {
                if (b.numcopies > 0)
                {found = 2;
                    b.numcopies -=1;
                    break;
                }else 
                {
                    found = 1;
                }

            }
        }
    }
    if (found == 0) {
        bookFound="Sorry, this book is not in our catalog.";
    } else if (found == 1) {
        bookFound="Sorry, this book is already borrowed.";
    } else if (found == 2) {
        bookFound="You successfully borrowed ";      
    }   

    return bookFound; 

}
public String returnBook(String returnedBook)
{
     int found = 0;
     boolean borrowed = false;
    String bookreturn = "\n";
    for (Book b : collection)
            {
        if (b.getTitle().equals(returnedBook)) 
        {
            if (found == 0) 
            {
                found = 1;
            }
            if (!b.isBorrowed()) 
            {
                b.borrowed=true;
                found = 2;
                b.numcopies +=1;
                break;
            }
        }
    }
    if (found == 0) {
        bookreturn="Sorry, this book is not in our catalog.";
    } else if (found == 1) {
        bookreturn="Please try again.";
    } else if (found == 2) {
        bookreturn="You successfully returned the book ";      
    }   

    return bookreturn; 

}
}

当你借书时,你应该像这样设置借阅标志:

 if (!b.isBorrowed()) {
    b.borrowed = true;
    ..

当你 return 这本书时,你应该

if (!b.isBorrowed()) {
     b.borrowed=false;//its returned now and can be borrowed

您可以使用图书馆中同一本书的副本数来扩展逻辑。