I'm trying to make a dictionary program using linked lists. I need four classes, one that holds the word and the meaning. One that creates the node of information and its link field. Another class that creates and maintains a linked list of words and their meanings. And then a test class.
so far I havepublic class WordMeaning { String theword; String def; WordMeaning(String t, String d) { theword = t; def = d; } String getword() { return theword; } String getdef() { return def; } }
public class WordMeaningNode { WordMeaning word; WordMeaning next; WordMeaningNode(WordMeaning w) { word = w; next = null; } }
public class WordList { WordMeaningNode list; WordList() { list = null; } void add(WordMeaning a) { WordMeaningNode temp = new WordMeaningNode(a); temp.next = list; list = temp; } void add2(WordMeaning a2) //appending to a list { WordMeaningNode temp = new WordMeaningNode(a2); if (listIsEmpty()) { list = temp; } else { WordMeaningNode curr = list; while(curr.next != null) { curr = curr.next; } curr.next = temp; } } boolean listIsEmpty() { boolean empty; if(list == null) { empty = true; } else { empty = false; } return empty; } }
Not sure why i'm getting errors in the list class in the add methods.