Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Need help getting these 4 Tests to PASS in the Reader.java file. Thank you in advance. ~ Book.java import java.time.LocalDate; public class Book { public

Need help getting these 4 Tests to PASS in the Reader.java file. Thank you in advance.

image text in transcribed

~ Book.java

import java.time.LocalDate; public class Book { public Integer ISBN_; public Integer TITLE_; public Integer SUBJECT_; public Integer PAGE_COUNT_; public Integer AUTHOR_; public Integer DUE_DATE_; private String mISBN; private String mTitle; private String mSubject; private Integer mPageCount; private String mAuthor; private LocalDate mDueDate; public Book(String mISBN, String mTitle, String mSubject, Integer mPageCount, String mAuthor, LocalDate mDueDate) { this.mISBN = mISBN; this.mTitle = mTitle; this.mSubject = mSubject; this.mPageCount = mPageCount; this.mAuthor = mAuthor; this.mDueDate = mDueDate; } public String getmISBN() { return mISBN; } public void setmISBN(String mISBN) { this.mISBN = mISBN; } public String getmTitle() { return mTitle; } public void setmTitle(String mTitle) { this.mTitle = mTitle; } public String getmSubject() { return mSubject; } public void setmSubject(String mSubject) { this.mSubject = mSubject; } public Integer getmPageCount() { return mPageCount; } public void setmPageCount(Integer mPageCount) { this.mPageCount = mPageCount; } public String getmAuthor() { return mAuthor; } public void setmAuthor(String mAuthor) { this.mAuthor = mAuthor; } public LocalDate getmDueDate() { return mDueDate; } public void setmDueDate(LocalDate mDueDate) { this.mDueDate = mDueDate; } @Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; Book book = (Book) o; if (mISBN != null ? !mISBN.equals(book.mISBN) : book.mISBN != null) return false; if (mTitle != null ? !mTitle.equals(book.mTitle) : book.mTitle != null) return false; if (mSubject != null ? !mSubject.equals(book.mSubject) : book.mSubject != null) return false; if (mPageCount != null ? !mPageCount.equals(book.mPageCount) : book.mPageCount != null) return false; if (mAuthor != null ? !mAuthor.equals(book.mAuthor) : book.mAuthor != null) return false; return mDueDate != null ? mDueDate.equals(book.mDueDate) : book.mDueDate == null; } @Override public int hashCode() { int result = mISBN != null ? mISBN.hashCode() : 0; result = 31 * result + (mTitle != null ? mTitle.hashCode() : 0); result = 31 * result + (mSubject != null ? mSubject.hashCode() : 0); result = 31 * result + (mPageCount != null ? mPageCount.hashCode() : 0); result = 31 * result + (mAuthor != null ? mAuthor.hashCode() : 0); result = 31 * result + (mDueDate != null ? mDueDate.hashCode() : 0); return result; } @Override public String toString() { return "Book{" + "mISBN='" + mISBN + '\'' + ", mTitle='" + mTitle + '\'' + ", mAuthor='" + mAuthor + '\'' + '}'; } }

~ Reader.java

import java.util.List; public class Reader { public Integer CARD_NUMBER_; public Integer NAME_; public Integer PHONE_; public Integer BOOK_COUNT_; public Integer BOOK_START_; private Integer cardNumber; private String name; private String phone; private List books; public Reader(Integer cardNumber, String name, String phone) { this.cardNumber = cardNumber; this.name = name; this.phone = phone; } public Code addBook(Book book) { if(hasBook(book)) { return Code.BOOK_ALREADY_CHECKED_OUT_ERROR; } books.add(book); return Code.SUCCESS; } public Code removeBook(Book book) { if(!hasBook(book)) { return Code.READER_DOESNT_HAVE_BOOK_ERROR; } try { books.remove(book); } catch (Exception e) { return Code.READER_COULD_NOT_REMOVE_BOOK_ERROR; } return Code.SUCCESS; } public boolean hasBook(Book book) { for(Book b: books) { if(b.equals(book)) { return true; } } return false; } public Integer getBookCount() { return books.size(); } public List getBooks() { return books; } public void setBooks(List books) { this.books = books; } public Integer getCardNumber() { return cardNumber; } public void setCardNumber(Integer cardNumber) { this.cardNumber = cardNumber; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getPhone() { return phone; } public void setPhone(String phone) { this.phone = phone; } @Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; Reader reader = (Reader) o; if (getCardNumber() != null ? !getCardNumber().equals(reader.getCardNumber()) : reader.getCardNumber() != null) return false; if (getName() != null ? !getName().equals(reader.getName()) : reader.getName() != null) return false; return getPhone() != null ? getPhone().equals(reader.getPhone()) : reader.getPhone() == null; } @Override public int hashCode() { int result = getCardNumber() != null ? getCardNumber().hashCode() : 0; result = 31 * result + (getName() != null ? getName().hashCode() : 0); result = 31 * result + (getPhone() != null ? getPhone().hashCode() : 0); return result; } @Override public String toString() { return name + " (#" + cardNumber + ") has checked out " + getBooks().toString().substring(1, getBooks().toString().length()-1) + "}"; } }

~ Code.java

public enum Code { /** * The following codes are returned based on condition in the library project. */ SUCCESS(0, "Transaction was a success"), FILE_NOT_FOUND_ERROR(-1, "Could not the file"), BOOK_COUNT_ERROR(-2, "Incorrect book count"), LIBRARY_ERROR(-3, "problem with the library"), LIBRARY_OUT_OF_BOOKS_ERROR(-31, "No books in library"), LIBRARY_OUT_OF_SHELVES_ERROR(-32, "No shelves for books"), BOOK_ALREADY_CHECKED_OUT_ERROR(-21, "Book already checked out error"), BOOK_LIMIT_REACHED_ERROR(-22, "Book limit reached"), BOOK_NOT_IN_INVENTORY_ERROR(-23, "book not in stacks or library"), READER_COUNT_ERROR(-4, "Reader Count Error"), READER_CARD_NUMBER_ERROR(-41, "Reader Card number error"), READER_PHONE_NUMBER_ERROR(-43,"Reader Phone number error"), READER_NOT_IN_LIBRARY_ERROR(-44,"Reader Phone number error"), READER_DOESNT_HAVE_BOOK_ERROR(-45, "Reader doesn't have book error"), READER_COULD_NOT_REMOVE_BOOK_ERROR(-46, "Reader won't let go of the book"), SHELF_COUNT_ERROR(-6,"Shelf count error"), SHELF_NUMBER_PARSE_ERROR(-61,"Shelf Number parse error"), SHELF_EXISTS_ERROR(-62,"shelf exists error"), SHELF_SUBJECT_MISMATCH_ERROR(-63,"Subjects do not match"), PAGE_COUNT_ERROR(-8,"Page count error"), DUE_DATE_ERROR(-10,"Due date error"), DATE_CONVERSION_ERROR(-101, "Date conversion Error"), NOT_IMPLEMENTED_ERROR(-99,"Not yet implemented error"), UNKNOWN_ERROR(-999, "Unknown Error"); private final int code; private final String message; Code(int code, String message) { this.code = code; this.message = message; } public int getCode() { return code; } public String getMessage() { return message; } } 
addBook test To test this class the Book class will need to be completed. 1. Add a Book to the Reader and check the status code. 2. The first time the book is added an assertEquals(reader.addBook (book), Code. SUCCESS) will pass 3. A second attempt to add the book will result in assertNotEquals passing when compared to a Code. Success 4. A second attempt to add the book will result in assertEquals passing when compared to Code. BOOK_ALREADY_CHECKED_OUT_ERROR; getBookCount_Test To test this class the Book class will need to be completed. 1. Create a Reader object. a. Assert that book count is 0 2. Add a Book to the Reader object a. Assert that book count is 1 3. Remove a Book from the Reader a. Assert that bookCount is O hasBook test 1. Create a Book 2. Use hasBook to check if the Reader has the book, should return false a. assertFalse should pass 3. Use addBook to add the book to the Reader 4. hasBook should now return true a. assert True should pass removeBook test 1. Ensure that assertEquals passes when compared to Code. READER_DOESNT_HAVE_BOOK_ERROR before a Book is added 2. Add a book 3. Ensure that assertEquals passes when compared to when Code. SUCCESS removing the

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

Brief the importance of span of control and its concepts.

Answered: 1 week ago

Question

What is meant by decentralisation?

Answered: 1 week ago

Question

Write down the Limitation of Beer - Lamberts law?

Answered: 1 week ago

Question

Discuss the Hawthorne experiments in detail

Answered: 1 week ago

Question

Explain the characteristics of a good system of control

Answered: 1 week ago