-
Notifications
You must be signed in to change notification settings - Fork 0
Library is finished(without getBooksByCategor function #8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
fb4334e
Library is finished(without getBooksByCategor function
fndrmh 0852d93
Update src/model/Library.java
fndrmh 4bf567a
Update src/model/Library.java
fndrmh cdec9c8
Update src/model/Library.java
fndrmh c208af3
Library fixed (try 2)
fndrmh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); | ||
| 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; | ||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.