Question
Trying to create a Library in Java 8 using the Date API. BookCopy has an associated DueDate (which is null if the book is not
Trying to create a Library in Java 8 using the Date API.
BookCopy has an associated DueDate (which is null if the book is not checked out)
and LibraryCard has a non-negative balance, which is incurred if books are checked in past their due dates. The library charges $.10 per day per book.
Modify your checkOut method ( which I named removeBookCopy() ) to give the BookCopy a due date that is equal to three weeks from the day that the books are checked out.
Modify your checkIn method ( which I named addBookCopy() )to check if the book is overdue; if so, update the balance accordingly.
Note: although a real library application would use only the real date, for ease of testing and debugging, ALSO create an additional checkIn and checkOut method that takes a date as a parameter, so that you don't have to wait three weeks to test your code.
Also create the following LibraryCard methods:
- a renewal method which allows the cardholder to get a new due date for that book. Renewal periods are in two-week increments.
- a method which takes a date as a parameter and returns a list of books that are due on or before that date.
- a method that checks if any books are overdue. (Note: although in a real-world application, this would check for overdue books using today's date, ALSO create an additional method that takes a date as a parameter for ease of testing.)
- a method that returns a list of all the books checked out, sorted by due date. (You may use an array or an ArrayList -- we're not focusing on the specific data structures yet.)
This is my code so far.
//Book class stores the title, author and ISBN of the book public class Book { private String Title; private String Author; //Using String for ISBN instead of a int because it is 13 digits long private String Isbn; //Constructor public Book(String title, String author, String isbn) { Title = title; Author = author; Isbn = isbn; } //No need for setters because a book's title, author and ISBN will never change //Getters public String getTitle() { return Title; } public String getAuthor() { return Author; } public String getIsbn() { return Isbn; } }
********************************************************************************
//BookCopy class stores the current copy of the book that is being checked in or out and the current library card that is being used. public class BookCopy { private Book Book; private LibraryCard LibraryCard; //Constructor //If book is not checked out, pass null for library card public BookCopy(Book book, LibraryCard libraryCard) { Book = book; LibraryCard = libraryCard; } //Getters and setters public Book getBook() { return Book; } public LibraryCard getLibraryCard() { return LibraryCard; } //We don't need setter for Book as a book's copy won't change //But we need setter for LibraryCard, as multiple people can borrow //a single book copy public void setLibraryCard(LibraryCard libraryCard) { LibraryCard = libraryCard; } }
**********************************************************************
//LibraryCard class stores the library card holder's ID, name and a list of the books that are currently checked out on the card //Prints the user and checkout information onto the console import java.util.*;
public class LibraryCard {
private int ID; private String CardHolderName; //List that stores the books that are checked out on the card private ArrayList
*******************************************************************************************
//Test program for the Book class, Library class and BookCopy class public class Main { public static void main (String[] args) throws java.lang.Exception { //List of Books and their bookCopies Book Book1 = new Book("Diary of a Wimpy Kid # 11: Double Down", "Jeff Kinney", "9781419723445"); BookCopy BookCopy1a = new BookCopy(Book1, null); BookCopy BookCopy1b = new BookCopy(Book1, null); Book Book2 = new Book("A Man Called Ove: A Novel", "Fredrik Backman", "9781476738024"); BookCopy BookCopy2a = new BookCopy(Book2, null); BookCopy BookCopy2b = new BookCopy(Book2, null); Book Book3 = new Book("To Kill a Mockingbird", "Harper Lee", "9780446310789"); BookCopy BookCopy3a = new BookCopy(Book3, null); BookCopy BookCopy3b = new BookCopy(Book3, null); Book Book4 = new Book("A Dance with Dragons", "George R. R. Martin", "9780553801477"); BookCopy BookCopy4a = new BookCopy(Book4, null); BookCopy BookCopy4b = new BookCopy(Book4, null); Book Book5 = new Book("One Flew Over the Cuckoo's Nest", "Ken Kesey", "9780451163967"); BookCopy BookCopy5a = new BookCopy(Book5, null); BookCopy BookCopy5b = new BookCopy(Book5, null); Book Book6 = new Book("The Amber Spyglass: His Dark Materials", "Philip Pullman", "9780440418566"); BookCopy BookCopy6a = new BookCopy(Book6, null); BookCopy BookCopy6b = new BookCopy(Book6, null); Book Book7 = new Book("The Help", "Kathryn Stockett", "9780399155345"); BookCopy BookCopy7a = new BookCopy(Book7, null); BookCopy BookCopy7b = new BookCopy(Book7, null); Book Book8 = new Book("Of Mice and Men", "John Steinbeck", "9780140177398"); BookCopy BookCopy8a = new BookCopy(Book8, null); BookCopy BookCopy8b = new BookCopy(Book8, null); Book Book9 = new Book("Harry Potter and the Deathly Hallows", "J. K. Rowling", "9780545010221"); BookCopy BookCopy9a = new BookCopy(Book9, null); BookCopy BookCopy9b = new BookCopy(Book9, null); Book Book10 = new Book("A Thousand Splendid Suns", "Khaled Hosseini", "9781594489501"); BookCopy BookCopy10a = new BookCopy(Book10, null); BookCopy BookCopy10b = new BookCopy(Book10, null); //Library Cards LibraryCard libraryCard1 = new LibraryCard(1, "Tony Stark", null); LibraryCard libraryCard2 = new LibraryCard(2, "Bruce Wayne", null); LibraryCard libraryCard3 = new LibraryCard(3, "Jon Snow", null); libraryCard1.addBookCopy(BookCopy6a); libraryCard1.addBookCopy(BookCopy6b); libraryCard1.addBookCopy(BookCopy5a); libraryCard2.addBookCopy(BookCopy3b); libraryCard3.addBookCopy(BookCopy4a); //This book has been borrowed by libraryCard1Holder libraryCard1.removeBookCopy(BookCopy6a); //This book hasn't been borrowed by libraryCard3Holder libraryCard3.removeBookCopy(BookCopy9b); } }
********************************************************************************
Output:
CheckOut Information: Borrower Name: Tony Stark Book Title: The Amber Spyglass: His Dark Materials Author Name: Philip Pullman ISBN No.: 9780440418566
CheckOut Information: Borrower Name: Tony Stark Book Title: The Amber Spyglass: His Dark Materials Author Name: Philip Pullman ISBN No.: 9780440418566
CheckOut Information: Borrower Name: Tony Stark Book Title: One Flew Over the Cuckoo's Nest Author Name: Ken Kesey ISBN No.: 9780451163967
CheckOut Information: Borrower Name: Bruce Wayne Book Title: To Kill a Mockingbird Author Name: Harper Lee ISBN No.: 9780446310789
CheckOut Information: Borrower Name: Jon Snow Book Title: A Dance with Dragons Author Name: George R. R. Martin ISBN No.: 9780553801477
Book Checkd In Successfully: Book Title: The Amber Spyglass: His Dark Materials
This book is not borrowed by Jon Snow
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started