In this homework you will implement a Library class that use

In this homework you will implement a Library class that uses your Book and Person class from homework 2. with slight modifications. The Library class will keep track of people with membership and the books that they have checked out. Book.java You will need to modify your Book java from homework 2 in the following ways: field: dueDate (private) A String containing the date book is due. Dates are given in the format \"DD MM YYYY\", such as \"01 02 2017\" (Feb. 1, 2017.) This will help when calculating the number of days a book is overdue. Field: checkedOut (private) A Boolean that is true if the book is checked out and false otherwise. Field: bookld (private) An int that holds the unique Id for the book. Because it is unique it will not be changed so you can declare it as final. This will be used to distinguish separate copies of the same book (with the same title and author). Field: bookValue (private) A double that holds the current value of the book in dollars. Replace the old constructor with one that has the following method hearder public Book(String title. String author, int bookld. double bookValue) Add accessors and mutators for each of the new fields except for a mutator for bookld. Note that getters for boolean fields use \"is\" instead of the normal \"get\". For example the getter for checkedOut in the book class should be called isCheckedOut(). Update the equals method to only use the bookld since it is unique for each book. We do this because it is possiblie to have multiple copies of the same book (same title and author) and in this set up they would not be equal. Also, update the toString method. Per son. java You will need to modify your Person.java from homework 2 in the following ways: Field: address (private) A String that contains the address for the person, e.g. \"101 Main St.\" For simplicity, do not worry about including the city, state, or zip code. Field: libraryCardNum (private) An int that is the unique library id number for the person. Note that this replaces the id field from homework 2. Once this is set it will never change, so you can make if final if you would like. Change the old constructor so that it has the following header and sets the correct fields: public Person(String name. String address, int libraryCardNum) Create accessors for the fields and mutators for the address field. Update equals method and toString. The Array Li st will now be called checkedOut and be a list of books the Person has checked out from the library. The addBook method will change slightly (see below). You can update the other methods as needed but they will not be used for this assignment and they will not be tested, public boolean addBook(Book b) Add the Book b to the list of the current object\'s checked out books if and only if it was net already in that list. Return true if the Book was added; return false if it was not added.

Solution

Solution:

Please find the implementation of the two classes.

Since both the constructors were supposed to be modified on the basis of the previous implementations, but since the code was not provided so the feilds mentioned in previous constructor implementation have also been included. The other common methods like toString() has also been implemented in the default format only as no format was specified. Please modify if needed.

Book.java

import java.util.ArrayList;
import java.util.List;

public class Book {

private String title;
private String author;
private String dueDate;
private boolean checkedOut;
private final int bookId;
private double bookValue;

public Book(String title, String author, String dueDate, boolean checkedOut, int bookId, double bookValue) {
this.title = title;
this.author = author;
this.dueDate = dueDate;
this.checkedOut = checkedOut;
this.bookId = bookId;
this.bookValue = bookValue;
}

public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}

public String getAuthor() {
return author;
}
public void setAuthor(String author) {
this.author = author;
}

public String getDueDate() {
return dueDate;
}
public void setDueDate(String dueDate) {
this.dueDate = dueDate;
}

public boolean isCheckedOut() {
return checkedOut;
}
public void setCheckedOut(boolean checkedOut) {
this.checkedOut = checkedOut;
}

public int getBookId() {
return bookId;
}

public double getBookValue() {
return bookValue;
}
public void setBookValue(double bookValue) {
this.bookValue = bookValue;
}

@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + bookId;
return result;
}

@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Book other = (Book) obj;
if (bookId != other.bookId)
return false;
return true;
}

@Override
public String toString() {
return \"Book [dueDate=\" + dueDate + \", checkedOut=\" + checkedOut + \", bookId=\" + bookId
+ \", bookValue=\" + bookValue + \"]\";
}

}

Person.java

import java.util.ArrayList;
import java.util.List;

public class Person {

private String name;
private String address;
private final int libraryCardNum;

public Person(String name, String address, int libraryCardNum) {
this.name = name;
this.address = address;
this.libraryCardNum = libraryCardNum;
}

public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}

public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}

public int getLibraryCardNum() {
return libraryCardNum;
}

@Override
public String toString() {
return \"Person [name=\" + name + \", address=\" + address + \", libraryCardNum=\" + libraryCardNum
+ \"]\";
}

@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((address == null) ? 0 : address.hashCode());
result = prime * result + libraryCardNum;
result = prime * result + ((name == null) ? 0 : name.hashCode());
return result;
}

@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Person other = (Person) obj;
if (address == null) {
if (other.address != null)
return false;
} else if (!address.equals(other.address))
return false;
if (libraryCardNum != other.libraryCardNum)
return false;
if (name == null) {
if (other.name != null)
return false;
} else if (!name.equals(other.name))
return false;
return true;
}


//The implementation is not complete properly as
//there is no clear detail about the ArrayList<Book>
//and from where it is comming from or where it is stored.
//A generic kind of implementation is written as per the requrement.
public boolean addBook (Book b){
List<Book> checkedOutBookList = new ArrayList<Book>();
return checkedOutBookList != null && !checkedOutBookList.contains(b)? true : false;
}
}

 In this homework you will implement a Library class that uses your Book and Person class from homework 2. with slight modifications. The Library class will kee
 In this homework you will implement a Library class that uses your Book and Person class from homework 2. with slight modifications. The Library class will kee
 In this homework you will implement a Library class that uses your Book and Person class from homework 2. with slight modifications. The Library class will kee
 In this homework you will implement a Library class that uses your Book and Person class from homework 2. with slight modifications. The Library class will kee

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site