Hi Everyone. I'm in the middle coding something and I hit a wall and don't know how to get past it. What I'm trying to do is the following:
I have a constructor of name "WordDetails" and I have several methods in it like "AddPage", "AddName", and "PrintName". I made a linked list of type "WordDetails" and created 1 link in the list. I added the 1st element in the list into a hash table using the string "One" as the key and the 0th element in the list as the value being added to the table. I need to know how access it so I can run any method from it from the hash table. Here is my code:
//[I]The Constructor[/I] //------------------------------------------------------------------------------------------------------------------- import java.util.*; import java.lang.*; import java.io.*; public class WordDetails { public String WordName; public LinkedList <Integer>PageNumbers = new LinkedList<Integer>(); public WordDetails() { } //Checks and eliminates same numbers in the list public void CheckNumbers() { if(PageNumbers.size() > 1) { for(int i = 0; i < (PageNumbers.size() - 1); i++) { if(PageNumbers.get(i) == PageNumbers.get(i+1)) { PageNumbers.remove(i+1); } } } } public void AddPage(int x) { PageNumbers.add(x); CheckNumbers(); } public void AddName(String Word) { WordName = Word; } public void PrintName() { System.out.println(WordName); } } //------------------------------------------------------------------------------------------------------------------- //[I]The Main Class[/I] //------------------------------------------------------------------------------------------------------------------- import java.io.*; import java.util.*; import java.lang.*; public class IndexForABook { public static void main (String args[]) throws Exception { Hashtable WordList = new Hashtable(); LinkedList <WordDetails>TempList = new LinkedList<WordDetails>(); TempList.add(new WordDetails()); WordList.put("One",TempList.get(0)); //[B][I]Here is where I would need to know how to access methods in the instance of the[/I][/B] //[B][I] constructor I added to the hash table[/I][/B] } //-------------------------------------------------------------------------------------------------------------------