上遇到此方法有问题。任何人都可以发现明显的错误?当我运行该程序并要求我输入要编辑的ID时,我输入了一个正确的ID,但它说“此ID已存在”..我只想说在编辑本书的ID后,如果说得通。任何帮助非常感谢。图书馆应用程序。在编辑书籍方法
public void editBook(ArrayList<Book> books) {
boolean exsistingID = false;
int editID, ID;
String newTitle, newAuthor, newPublisher;
int newReleaseYear;
//int newNumLoans;
//boolean newOnLoan;
do {
System.out.println("Enter the ID of the book you wish to edit: ");
editID = scan.nextInt();
scan.nextLine();
if (editID == 0) {
System.out.println("ERROR - Book ID can not be 0. Please try again");
}
} while (editID == 0);
for (int a = 0; a < books.size(); a++) {
Book z = books.get(a);
if (editID == (z.getBookID())) {
exsistingID = true;
break;
}
}
if (exsistingID == true) {
System.out.println("This ID already exists. Please try again");
do {
System.out.println("Enter a new ID: ");
ID = scan.nextInt();
scan.nextLine();
if (ID == 0) {
System.out.println("ERROR - Book ID can not be 0. Please try again");
}
} while (ID == 0);