[Solved]Goal Week Implement Hashedtable Book Object Attached Hashedtable Following Array Size 31 E Q37243395
Our goal this week is to implement our own HashedTable for BookObject (attached below)
Your HashedTable should do the following:
- Have an array of size 31. Each element should be a LinkedList(use Java’s built-in LinkedList to save time/effort) to handlecollisions via chaining.
- Have an add() method which takes in a key anda value:
- Uses the Book’s title as your key. Since the Book’s title is aString, convert the Book’s title to an integer (use the Stringtitle’s hashCode() method). NOTE: Youmay want to apply Math.abs() to this result!
- Takes the resulting has of the title and mod it by 31 todetermine which array index the book should be placed in. And thenadd the Book to the LinkedList at that location.
- Has a get() method which only takes in a key:
- Uses the Book’s title as your key. Use the hashCode() method ofthe title and mod the result by 31 to find the correct list in thearray, and then check each item in the linked list to see if thatitem is your target.
- If you find the target, return the Book; if not, return anull.
- Has a toString() method to print out thecontents of the HashedTable
When testing your code, make sure to verify that it handlescollisions correctly.
This is a book Object:
*/
public class Book implements Enjoyable
{
private String title;
private int pageCount;
private int wordCount;
// Book Constructor
public Book() {
setTitle(“Undefined”);
setPageCount(-1);
setWordCount(-1);
}
@Override
public int enjoy() {
return pageCount / 50;
}
/**
* Sets the Book’s Title
* @param inTitle String to set the Title as
*/
public void setTitle(String inTitle) {
title = inTitle;
}
/**
* Sets the Book’s Page Title
* @param inPageCount Number to set the Page Count
*/
public void setPageCount(int inPageCount) {
if (inPageCount > 0) {
pageCount = inPageCount;
}
}
/**
* Sets the Book’s Page Count
* @param inWordCount Number to set the Word Count
*/
public void setWordCount(int inWordCount) {
if (inWordCount > 0) {
wordCount = inWordCount;
}
}
/**
* Returns the Book’s Title
* @return Number of Pages
*/
public String getTitle() {
return title;
}
/**
* Returns the Book’s Page Count
* @return Number of Pages in the Book
*/
public int getPageCount() {
return pageCount;
}
/**
* Returns the Book’s Word Count
* @return Number of Words in the Book
*/
public int getWordCount() {
return wordCount;
}
/**
* Returns a String describing the Book
* @return String describing the Book
*/
public String toString() {
return “The title of this book is: ” + getTitle() + “.ntIt has “+ getPageCount() + ” pages and contains ” + getWordCount() + “words.ntThis book generates ” + enjoy() + ” units of joy.”;
}
}
……………………
ENJOYABLE INTERFACE
/**
* This Interface is for objects that are enjoyable
*/
public interface Enjoyable
{
/**
* The enjoy method will attempt to use the object forenjoyment
* @return This method will return the amount of joy produced fromenjoying the object
*/
public int enjoy();
}
Expert Answer
Answer to Our goal this week is to implement our own HashedTable for Book Object (attached below) Your HashedTable should do the f… . . .
OR

