上遇到此方法有問題。任何人都可以發現明顯的錯誤?當我運行該程序並要求我輸入要編輯的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);