Question: import java.util.HashMap; import Utilities.Code; public class Shelf { public static final int SHELF _ NUMBER _ = 0 ; public static final int SUBJECT _
import java.util.HashMap;
import Utilities.Code;
public class Shelf
public static final int SHELFNUMBER;
public static final int SUBJECT;
private HashMap books new HashMap;
private int shelfNumber;
private String subject;
@Deprecated
public Shelf
public Shelfint shelfNumber, String subject
this.shelfNumber shelfNumber;
this.subject subject;
public int getBookCountBook 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
public Code addBookBook book
Adds the parameter 'book' to the HashMap of books stored on the shelf
If the book already exists in the HashMap, 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 and return a SUCCESS Code.
If the book does NOT exist on the shelf, and the subject DOES NOT match, return a SHELFSUBJECTMISMATCHERROR 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 removeBookBook book
If the parameter book is not present in the books hashMap, return a BOOKNOTININVENTORYERROR Code and print a message like
Hitchhikers Guide To the Galaxy is not on shelf scifi
If the parameter book IS present in the books hashMap but has a count of return a BOOKNOTININVENTORYERROR Code and print a message like
No copies of Hitchhikers Guide To the Galaxy remain on shelf scifi
If the parameter book is in the books hashMap and the count is greater than 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 scifi
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:
books on shelf: : education
Headfirst Java by Grady Booch ISBN:
book on shelf: : Adventure
Count of Monte Cristo by Alexandre Dumas ISBN:
books on shelf: : scifi
Hitchhikers Guide To the Galaxy by Douglas Adams ISBN:w
Dune by Frank Herbert ISBN:w
@Override
public String toString
return shelfNumber : subject;
public HashMap getBooks
return books;
public void setBooksHashMap books
this.books books;
public int getShelfNumber
return shelfNumber;
public void setShelfNumberint shelfNumber
this.shelfNumber shelfNumber;
public String getSubject
return subject;
public void setSubjectString subject
this.subject subject;
@Override
public boolean equalsObject o
if this o return true;
if o null getClass ogetClass return false;
Shelf shelf Shelf o;
if getShelfNumber shelf.getShelfNumber return false;
return getSubject null getSubjectequalsshelfgetSubject : shelf.getSubject null;
@Override
public int hashCode
int result getShelfNumber;
result result getSubject null getSubjecthashCode : ;
return result;
Library Project: Shelf.java
V
UML Diagram of Shelf.java
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
