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 SHELF_NUMBER_=0;
public static final int SUBJECT_=1;
private HashMap books = new HashMap();
private int shelfNumber;
private String subject;
@Deprecated
public Shelf(){
}
public Shelf(int shelfNumber, String subject){
this.shelfNumber = shelfNumber;
this.subject = 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**
public Code addBook(Book 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 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:13372
1 book on shelf: 3 : Adventure
Count of Monte Cristo by Alexandre Dumas ISBN:52971
3 books on shelf: 1 : sci-fi
Hitchhikers Guide To the Galaxy by Douglas Adams ISBN:42-w-872
Dune by Frank Herbert ISBN:34-w-341
}
@Override
public String toString(){
return shelfNumber +" : "+ subject;
}
public HashMap getBooks(){
return books;
}
public void setBooks(HashMap books){
this.books = books;
}
public int getShelfNumber(){
return shelfNumber;
}
public void setShelfNumber(int shelfNumber){
this.shelfNumber = shelfNumber;
}
public String getSubject(){
return subject;
}
public void setSubject(String subject){
this.subject = subject;
}
@Override
public boolean equals(Object o){
if (this == o) return true;
if (o == null || getClass()!= o.getClass()) return false;
Shelf shelf =(Shelf) o;
if (getShelfNumber()!= shelf.getShelfNumber()) return false;
return getSubject()!= null ? getSubject().equals(shelf.getSubject()) : shelf.getSubject()== null;
}
@Override
public int hashCode(){
int result = getShelfNumber();
result =31* result +(getSubject()!= null ? getSubject().hashCode() : 0);
return result;
}
}
Library Project: Shelf.java
V2.4.2
UML Diagram of Shelf.java
 import java.util.HashMap; import Utilities.Code; public class Shelf { public static final

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!