Need help big time with hashtable!
Well, i have a problem facing me. I've to design a predictive text program which use's a keypad exactly the same on a phone. I'm in the middle of it now. i'm using a hashtable to store my dictionary and have a major problemi cant manage to get around.
// the 4669 stands for the letters on the phone. 4=ghi,6=mno,9=def
Hashtable pt_dictionary = new Hashtable();
void put()
{
pt_dictionary.put("4996", "good");
pt_dictionary.put("4996", "home");
pt_dictionary.put("4996", "gome");
pt_dictionary.put("4996", "hood");
pt_dictionary.put("4996", "hoof");
pt_dictionary.put("4996", "hone");
pt_dictionary.put("4996", "goof");
}
These are all the clashes when the user selects 4996. Above is the typical sequence they come out on a phone. But if a user use's home more times than good, home should be the first to be output. The only answer to this, i think, is as follows :
public class word_node//creates a node with amount of usuage for sorting
{
private String word;
private int usuage = 1;
public void node_word(String w, int u)//Constructor
{
word = w;
usuage = u;
}
public void word_node(word_node w_n)//Constructor
{
word = w_n.word;
usuage = w_n.usuage;
}
public void update_usuage()//updates the usuage
{
usuage++;
}
}
public void create_nodes()
{
word_node good(String good, int i=1);
word_node gone(String gone, int i=1);
word_node hood(String hood, int i=1);
word_node hoof(String hoof, int i=1);
word_node hone(String hone, int i=1);
word_node goof(String goof, int i=1);
}
public void create_Hashtable_&_put_in_values()
{
Hashtable pt_dictionary = new Hashtable();
pt_dictionary.put("4669", good);
pt_dictionary.put("4669", home);
pt_dictionary.put("4669", gone);
pt_dictionary.put("4669", hood);
pt_dictionary.put("4669", hoof);
pt_dictionary.put("4669", hone);
pt_dictionary.put("4669", goof);
}
Now, all word_node's in 4669 buckets have there usuage equal to 1. Now lets say the user uses home, "home.update_usuage()" updates the usuage and the next time 4669 is selected, home should be first option seen!. I can't for the life of me get the code to work for me. If anyone could help in anyway i would be so grateful,if its even possible!Cheers
King regards,
John Stafford

