Question: Must be coded in java, I need help with the getBookeCount, addBook, removeBook, and listBooks methods, I would like to see how one might code
Must be coded in java, I need help with the getBookeCount, addBook, removeBook, and listBooks methods, I would like to see how one might code this. import java.util.HashMap; import java.util.Objects; public class Shelf { public static final Integer SHELF_NUMBER_ = 0; public static final Integer SUBJECT_ = 0; /*These fields will hold an integer that will be used to index the values shown below. The values will be read from a String array that results from using the split() method on the comma separated Strings shown below. */ private int shelfNumber; private String subject; private HashMap books; /* HashMap books This holds an instance of each book, and the count of that book that is currently on the shelf. This means if the shelf normally holds a copy of a book, but they are all checked out, the book will be in the list but will have a count of 0. */ public Shelf() { System.out.println("Shelf not implemented"); // no-parameter constructor. The values will be initialized with the setter methods } 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 */ } public Code addBook(Book book){ /* 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){ /* 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(){ /* 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 */ String res = null; for(int i =0; i< books.keySet().size(); i++){ res = res + books.keySet().toString() + " "; } return getSHELF_NUMBER_()+res; } } 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
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
