Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Must be coded in java, I need help with the getBookCount, addBook, removeBook, and listBooks methods, I would like to see how one might code

Must be coded in java, I need help with the getBookCount, addBook, removeBook, and listBooks methods, I would like to see how one might code this. Shelf is not complete b/c that is what need assistance on. import java.util.HashMap; import java.util.Objects; 
public Shelf() { System.out.println("Shelf not implemented"); // no-parameter constructor. The values will be initialized with the setter methods } public int getSHELF_NUMBER_() { return SHELF_NUMBER_; } public void setSHELF_NUMBER_(int SHELF_NUMBER_) { this.SHELF_NUMBER_ = SHELF_NUMBER_; } public int getSUBJECT_() { return SUBJECT_; } public void setSUBJECT_(int SUBJECT_) { this.SUBJECT_ = SUBJECT_; } public HashMap getBooks() { return books; } public void setBooks(HashMap books) { this.books = books; } @Override public boolean equals(Object o) { if (this == o) return true; if (!(o instanceof Shelf)) return false; Shelf shelf = (Shelf) o; return shelfNumber == shelf.shelfNumber && subject.equals(shelf.subject); } @Override public int hashCode() { return Objects.hash(shelfNumber, subject, getBooks()); } @Override public String toString() { /* Returns a string that looks like: 2 : education Where 2 is the shelfNumber field and education is the subject. */ return SHELF_NUMBER_ + " : " + subject; } public int getBookCount(Book book){ /* This returns the count of the book parameter stored on the shelf. If the book is not stored on the shelf it should return a -1 */ return 0; } public Code addBook(Book book){ books.add(book); if(books.contains(book)) return Code.BOOK_ALREADY_CHECKED_OUT_ERROR; else return Code.SUCCESS; /* Adds the parameter 'book' to the list of books stored on the shelf If the book already exists on the shelf, the count should be incremented, and a SUCCESS code should be returned. If the book does NOT exist on the shelf, and the subject matches, add the book to the shelf, set the count of the book to 1, and return a SUCCESS Code. If the book does NOT exist on the shelf, and the subject DOES NOT match, return a SHELF_SUBJECT_MISMATCH_ERROR Code. If the book is successfully added, print a message that displays the toString for the Book, concatenated with " added to shelf " concatenated with the toString of the current Shelf. */ } public Code removeBook(Book book){ books.remove(book); if (books.contains(book);{ return Code.READER_DOESNT_HAVE_BOOK_ERROR; }else return Code.SUCCESS; } /* If the parameter book is not present in the books hashMap, return a BOOK_NOT_IN_INVENTORY_ERROR Code and print a message like Hitchhikers Guide To the Galaxy is not on shelf sci-fi If the parameter book IS present in the books hashMap but has a count of 0, return a BOOK_NOT_IN_INVENTORY_ERROR Code and print a message like No copies of Hitchhikers Guide To the Galaxy remain on shelf sci-fi If the parameter book is in the books hashMap and the count is greater than 0 decrement the count of books in the hashMap, return a SUCCESS Code and print a message like Hitchhikers Guide To the Galaxy successfully removed from shelf sci-fi */ } public String listBooks(){ String res = null; for(int i =0; i< books.keySet().size(); i++){ res = res + books.keySet().toString() + " "; } return getSHELF_NUMBER_()+res; /* Returns a String listing all of the books on the shelf. The listing of books should match the following (Each of the following is a separate shelf): 2 books on shelf: 2 : education Headfirst Java by Grady Booch ISBN:1337 2 1 book on shelf: 3 : Adventure Count of Monte Cristo by Alexandre Dumas ISBN:5297 1 3 books on shelf: 1 : sci-fi Hitchhikers Guide To the Galaxy by Douglas Adams ISBN:42-w-87 2 Dune by Frank Herbert ISBN:34-w-34 1 */ } }
 import java.time.LocalDate; import java.util.Objects; public class Book { //based off of UML // constants, used to index the values public static final Integer ISBN_ = null; public static final Integer TITLE_ = null; public static final Integer SUBJECT_ = null; public static final Integer PAGE_COUNT_ = null; public static final Integer AUTHOR_ = null; public static final Integer DUE_DATE_ = null; private String mISBN; private String mTitle; private String mSubject; private Integer mPageCount; private String mAuthor; private LocalDate mDueDate; // def constructor 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 Book() { this.mISBN = null; this.mTitle = null; this.mSubject = null; this.mPageCount = null; } 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(int mPageCount) { this.mPageCount = mPageCount; } public String getmAuthor() { return mAuthor; } public void setmAuthor(String mAuthor) { this.mAuthor = mAuthor; } public void setmDueDate(LocalDate mDueDate) { this.mDueDate = mDueDate; } public LocalDate getmDueDate() { return mDueDate; } // Compares everything & No dueDate @Override public boolean equals(Object o) { if (this == o) return true; if (!(o instanceof Book)) return false; Book book = (Book) o; return getmPageCount() == book.getmPageCount() && getmISBN().equals(book.getmISBN()) && getmTitle().equals(book.getmTitle()) && getmSubject().equals(book.getmSubject()) && getmAuthor().equals(book.getmAuthor()); } // No dueDate @Override public int hashCode() { return Objects.hash(getmISBN(), getmTitle(), getmSubject(), getmPageCount(), getmAuthor()); } public String toString() { return TITLE_ + " by " + AUTHOR_ + " ISBN: " + ISBN_; } // 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; } }

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

Essentials of Database Management

Authors: Jeffrey A. Hoffer, Heikki Topi, Ramesh Venkataraman

1st edition

133405680, 9780133547702 , 978-0133405682

More Books

Students also viewed these Databases questions