-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLibrary.java
More file actions
38 lines (33 loc) · 1.17 KB
/
Library.java
File metadata and controls
38 lines (33 loc) · 1.17 KB
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
27
28
29
30
31
32
33
34
35
36
37
38
import java.util.ArrayList;
public class Library {
private ArrayList<Book> books = new ArrayList<>();
public void addBook(Book book) {
books.add(book);
System.out.println("Book added: " + book.getTitle());
}
public void showAllBooks() {
for (Book book : books) {
System.out.println(book.getTitle() + " by " + book.getAuthor() + (book.isIssued() ? " [Issued]" : " [Available]"));
}
}
public void issueBook(String title) {
for (Book book : books) {
if (book.getTitle().equalsIgnoreCase(title) && !book.isIssued()) {
book.issueBook();
System.out.println("Book issued: " + title);
return;
}
}
System.out.println("Book not available or already issued.");
}
public void returnBook(String title) {
for (Book book : books) {
if (book.getTitle().equalsIgnoreCase(title) && book.isIssued()) {
book.returnBook();
System.out.println("Book returned: " + title);
return;
}
}
System.out.println("Book not found or not issued.");
}
}