-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathModifyBooks.java
More file actions
26 lines (22 loc) · 759 Bytes
/
ModifyBooks.java
File metadata and controls
26 lines (22 loc) · 759 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import java.util.ArrayList;
public class ModifyBooks {
public static void modifyBookTitle(ArrayList<Books> books, int id, String newTitle) {
if (books.size() == 0) {
System.out.println("There is no book in the list to modify. First add a book.");
return;
}
boolean modified = false;
for (Books book : books) {
if (book.getID() == id) {
book.setTitle(newTitle);
modified = true;
break;
}
}
if (modified) {
System.out.println("Book with ID " + id + " has been modified successfully.");
} else {
System.out.println("Could not find a book with ID " + id + ".");
}
}
}