Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
141 changes: 102 additions & 39 deletions src/model/Library.java
Original file line number Diff line number Diff line change
@@ -1,80 +1,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) {
// TODO: Implement method 'addBook'.
throw new UnsupportedOperationException("Unimplemented method 'addBook'");
books.add(book);
}

public void removeBook(String isbn) {
// TODO: Implement method 'removeBook'.
throw new UnsupportedOperationException("Unimplemented method 'removeBook'");
for (Book book : books) {
if(book.getIsbn().equals(isbn)){
books.remove(book);
}
}
}

public void searchBookByTitle(String title) {
// TODO: Implement method 'searchBookByTitle'.
throw new UnsupportedOperationException("Unimplemented method 'searchBookByTitle'");
public Book searchBookByTitle(String title) {
for(Book book : books){
if(book.getTitle().equals(title)){
return book;
}
}
return null;
}

public void searchBookByISBN(String isbn) {
// TODO: Implement method 'searchBookByISBN'.
throw new UnsupportedOperationException("Unimplemented method 'searchBookByISBN'");
public Book searchBookByISBN(String isbn) {
for(Book book : books){
if(book.getIsbn().equals(isbn)){
return book;
}
}
return null;
}

public void getAvailableBooks() {
// TODO: Implement method 'getAvailableBooks'.
throw new UnsupportedOperationException("Unimplemented method 'getAvailableBooks'");
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) {
// TODO: Implement method 'addStudent'.
throw new UnsupportedOperationException("Unimplemented method 'addStudent'");
students.add(student);
}

public void removeStudent(String studentId) {
// TODO: Implement method 'removeStudent'.
throw new UnsupportedOperationException("Unimplemented method 'removeStudent'");
for(Student student : students){
if(student.getStudentId().equals(studentId)){
students.remove(student);
}
}
}

public void searchStudentById(String studentId) {
// TODO: Implement method 'searchStudentById'.
throw new UnsupportedOperationException("Unimplemented method 'searchStudentById'");
public Student searchStudentById(String studentId) {
for(Student student : students){
if(student.getStudentId().equals(studentId)){
return student;
}
}
return null;
}

public void getAllStudents() {
// TODO: Implement method 'getAllStudents'.
throw new UnsupportedOperationException("Unimplemented method 'getAllStudents'");
public List<Student> getAllStudents() {
return students;
}

public void borrowBook(Book book, Student student) {
// TODO: Implement method 'borrowBook'.
throw new UnsupportedOperationException("Unimplemented method 'borrowBook'");
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 void returnBook(Book book) {
// TODO: Implement method 'returnBook'.
throw new UnsupportedOperationException("Unimplemented method 'returnBook'");
}

public void getBorrowedBooksByStudent(String studentId) {
// TODO: Implement method 'getBorrowedBooksByStudent'.
throw new UnsupportedOperationException("Unimplemented method 'getBorrowedBooksByStudent'");
public boolean returnBook(Book book) {
for(Loan loan :loans){
if(loan.getBook().equals(book)){
loans.remove(loan);
Comment thread
rzr8i marked this conversation as resolved.
loan.getBook().returnBook();
return true;
}
}
return false;
}

public void getBooksByCategory(String categoryName) {
// TODO: Implement method 'getBooksByCategory'.
throw new UnsupportedOperationException("Unimplemented method 'getBooksByCategory'");
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 getStudentsByMajor(String major) {
// TODO: Implement method 'getStudentsByMajor'.
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;
}
}