【发布时间】:2015-06-03 07:31:31
【问题描述】:
我已在我的图书馆系统中添加了一个返回功能,该功能成功运行。问题是,当你还书后去取出书时,它不成功,并说“书已经借了”。我正在努力解决这个问题。
这是我的系统“借书”和“还书”的代码...
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;
}
}
【问题讨论】:
-
借书码在哪里?
-
抱歉,到此为止。