-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLibrary.java
54 lines (46 loc) · 1.28 KB
/
Library.java
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import java.util.ArrayList;
import java.util.List;
public class Library {
private List<Book> books;
private List<Member> members;
public Library() {
this.books = new ArrayList<>();
this.members = new ArrayList<>();
}
public void addBook(Book book) {
books.add(book);
}
public void addMember(Member member) {
members.add(member);
}
public Book findBookByIsbn(String isbn) {
for (Book book : books) {
if (book.getIsbn().equals(isbn)) {
return book;
}
}
return null;
}
public Member findMemberById(String memberId) {
for (Member member : members) {
if (member.getMemberId().equals(memberId)) {
return member;
}
}
return null;
}
public void displayAvailableBooks() {
System.out.println("Available Books:");
for (Book book : books) {
if (book.isAvailable()) {
System.out.println(book);
}
}
}
public void displayMembers() {
System.out.println("Library Members:");
for (Member member : members) {
System.out.println(member);
}
}
}