I’m in a data structures class and we have an assignment that includes creating a hash table for a latin dictionary and on the getDefinition method in the LatinDictionary class (basically a wrapper) it asks for string back after an input of a string like so…
import java.util.Iterator;
import data_structures.*;
public class LatinDictionary {
private DictionaryADT<String,String> dictionary;
private int maxSize = DictionaryReader.entries.length;
....
public String getDefinition(String latinWord) {
return dictionary.getValue(latinWord);
}
The getValue method is as follows:
package data_structures;
import java.util.Iterator;
public class HashTable <K,V> implements DictionaryADT<K,V>{
private int maxSize,currentSize,tableSize;
private UnorderedList<DictionaryNode<K,V>>[] list;
DictionaryADT<String, String> dictionary;
...
public V getValue(K key){
int code = hashCode((String)key);
DictionaryNode temp = new DictionaryNode(key,null);
if(!list[code].contains(temp))return null;
DictionaryNode temp2 = new DictionaryNode(null, list[code].find(temp));
return (V) temp2.value;
}
and the find method from the unordered list class is as follows:
package data_structures;
import java.util.Iterator;
import java.util.NoSuchElementException;
public class UnorderedList<E> implements Iterable<E>{
public E find(E object) {
Node<E> current=head;
Node<E> previous = head;
Node<E> temp=null;
while(current!=null && ((Comparable<E>)object).compareTo((current.data))!=0){
previous=current;
current=current.next;
temp=current;
}
return temp.data;
}
The dictionaryADT is an interface provided and a specification is that the LatinDictionary will only reference the ADT object and not the hashtable itself.
Additionally, I cannot import java.util.*.
No matter what I try I keep getting a “cannot cast” error or something else depending on what I try but I can’t see how to get from a V to a string.
Unfortunately I can’t find ANYTHING on the internet relating to self-built hashtables let alone the sort of implementation I have to use here. Anything that has to do with hashtables uses the built-in version and not a self written one, which is of very little use. I have this project due in like 2 weeks but there are 3 other implementations to do after this one! Any help is greatly appreciated. Thanks.
I got it….instead of
it should be…