- 13th Feb 2024
- 21:40 pm
- Adan Salman
Java Assignment Question
In this assignment, you will produce a list of all words that have 6 or more anagrams. You will create a new class (LinkedDictionary that inherits from WordList as follows:
WordList |
|
– WordNode head |
head of linked list |
+ WordList() |
creates empty list |
+ void display() |
show contents of list |
+ void insert(Word w) |
insert w to front of list |
+ Word search(Word w) |
search for w in list; returns reference |
+ Word remove(Word w) |
remove first occurrence of w if exists |
LinkedDictionary |
|
|
|
+ LinkedDictionary(String f) |
read words from file and insert into list |
+ int countAnagrams(Word w) |
look through list and return count of w's anagrams |
+ void displayBigAnagramFamilies() |
display each word with 6+ anagrams |
For testing purposes you might use a hand-crafted data file with 20 or so words in it (some of which are anagrams). Once you have the program working you can use the provided data file found in the repository: data/mywords.txt (which has over 350,000 words).
You will also need to add a method to Word that will accept another Word object as a parameter and will return true if they are anagrams (false if not). We will use this function rather than.equals() because the latter has already been written to compare the words themselves rather than the sorted versions of the words.
Your solution should use the design specified above. The driver should create a LinkedDictionary and then display its big (6 or more) anagrams. You should add code in main to time actions of the program and display the result at the end. NOTE: When you run the program using the large dictionary file it will take quite a bit of time to finish.
Java Assignment Solution
import java.util.*; import java.io.*; class Word { String s; Word(String str) { s=str; } Boolean isAnagram(Word w) { char s1[]=this.s.toCharArray(), s2[]=w.s.toCharArray(); Arrays.sort(s1); Arrays.sort(s2); if(s1.length!=s2.length)return false; for(int i=0;i