Question: Please write these three methods in java. Class HashDictionary: This class implements a dictionary using a hash table with separate chaining. You will decide on
Please write these three methods in java.
Class HashDictionary:
This class implements a dictionary using a hash table with separate chaining. You will decide on the size of the table, keeping in mind that the size of the table must be a prime number. A table of size between 5000-10000, should work well.
You must design your hash function so that it produces few collisions. A bad hash function that induces many collisions will result in a lower mark. As mentioned above, you cannot use Javas hashCode() method in your hash function.
For this class, you must implement all the public methods in the following interface:
public interface DictionaryADT {
public int put(Configuration pair) throws DictionaryException;
public void remove(String config) throws DictionaryException;
public int getScore(String config); }
The descriptions of these methods follows:
public int put(Configuration data) throws DictionaryException: Inserts the given Configuration object referenced by data in the dictionary. This method must throw a DictionaryException (see below) if the configuration string stored in data, is already in the dictionary.
You are required to implement the dictionary using a hash table with separate chaining. To determine how good your design is, we will count the number of collisions produced by your hash function. Method put will return the value 1 if the insertion of the object referenced by data into the hash table produces a collision, and it will return the value 0 otherwise. In other words, if for example your hash function is h(key) and the name of your table is T, this method will return the value 1 if the list in T[h(data.getStringConfiguration())] already stores at least one element; it will return 0 if the list in T[h(data.getStringConfiguration())] was empty before the insertion.
public void remove(String config) throws DictionaryException: Removes the entry with configuration string config from the dictionary. Must throw a DictionaryException (see below) if the configuration is not in the dictionary.
public int getScore(String config): A method which returns the score stored in the dictionary for the given configuration string, or -1 if the configuration string is not in the dictionary
Hint. You might want to implement a class Node storing an object of type Configuration and a link object of type Node to construct the linked list associated to an entry of the hash table. You do not need to follow this suggestion. You can implement the lists associated with the entries of the table in any way you want.
provide java file:
public class Configuration {
private int score;
private String config;
public Configuration(int aScore, String aConfig) {
super();
score = aScore;
config = aConfig;
}
public int getScore() {
return score;
}
public String getStringConfiguration() {
return config;
}
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
