In this homework you will implement a Library class that use
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;
}
}



