-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLibrary.java
More file actions
143 lines (124 loc) · 3.56 KB
/
Library.java
File metadata and controls
143 lines (124 loc) · 3.56 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
package model;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
public class Library {
private List<Book> books;
private List<Student> students;
private List<Category> categories;
private List<Loan> loans;
//Constructor
public Library(){
books=new ArrayList<>();
students=new ArrayList<>();
categories=new ArrayList<>();
loans=new ArrayList<>();
}
public void addBook(Book book) {
books.add(book);
}
public void removeBook(String isbn) {
for (Book book : books) {
if(book.getIsbn().equals(isbn)){
books.remove(book);
}
}
}
public Book searchBookByTitle(String title) {
for(Book book : books){
if(book.getTitle().equals(title)){
return book;
}
}
return null;
}
public Book searchBookByISBN(String isbn) {
for(Book book : books){
if(book.getIsbn().equals(isbn)){
return book;
}
}
return null;
}
public List<Book> getAvailableBooks() {
List<Book> AvailableBooks=new ArrayList<>();
for(Book book : books){
if(!book.getIsBorrowed()){
AvailableBooks.add(book);
}
}
return AvailableBooks;
}
public void addStudent(Student student) {
students.add(student);
}
public void removeStudent(String studentId) {
for(Student student : students){
if(student.getStudentId().equals(studentId)){
students.remove(student);
}
}
}
public Student searchStudentById(String studentId) {
for(Student student : students){
if(student.getStudentId().equals(studentId)){
return student;
}
}
return null;
}
public List<Student> getAllStudents() {
return students;
}
public boolean borrowBook(Book book, Student student) {
if(book.getIsBorrowed()){
return false;
}
Date loanDate=new Date();
Calendar calendar= Calendar.getInstance();
calendar.setTime(loanDate);
calendar.add(Calendar.DAY_OF_MONTH,10);
Date dueDate = calendar.getTime();
book.borrowBook();
Loan loan=new Loan(book,student,loanDate,dueDate);
loans.add(loan);
return true;
}
public boolean returnBook(Book book) {
for(Loan loan :loans){
if(loan.getBook().equals(book)){
loans.remove(loan);
loan.getBook().returnBook();
return true;
}
}
return false;
}
public List<Book> getBorrowedBooksByStudent(String studentId) {
List<Book> borrowedBooks=new ArrayList<>();
for(Loan loan : loans){
if(loan.getStudent().studentId.equals(studentId)){
borrowedBooks.add(loan.getBook());
}
}
return borrowedBooks;
}
public void getBooksByCategory(String categoryName) {
/*for(Category category : categories){
if(category.getName().equals(categoryName)){
}
} */
// TODO: Implement method 'getStudentsByMajor'.
throw new UnsupportedOperationException("Unimplemented method 'getStudentsByMajor'");
}
public List<Student> getStudentsByMajor(String major) {
List<Student> studentsByMajor=new ArrayList<>();
for(Student student :students){
if(student.getMajor().equals(major)){
studentsByMajor.add(student);
}
}
return studentsByMajor;
}
}