Question: import java.io . * ; import java.util. * ; public class WordLookup { public static void main ( String [ ] args ) { /
import java.io;
import java.util.;
public class WordLookup
public static void mainString args
Initialize maps for dictionary and synonyms
Map dictionary new HashMap;
Map synonyms new HashMap;
Load data from files
loadDictionarydictionary;
loadSynonymssynonyms;
Prompt user for input
Scanner scanner new ScannerSystemin;
System.out.printlnEnter a word to look up:;
String inputWord scanner.nextLinetrimtoLowerCase;
Search for the word in dictionary and synonyms
if dictionarycontainsKeyinputWord
System.out.printlnDefinition of inputWord : dictionary.getinputWord;
Check for synonyms
if synonymscontainsKeyinputWord
System.out.printlnSynonyms for inputWord :;
for String synonym : synonyms.getinputWord
System.out.println synonym : ;
else
System.out.printlnNo synonyms found for inputWord;
else
System.out.printlnWord not found in the dictionary: inputWord;
Method to load dictionary from file
private static void loadDictionaryMap dictionary
try BufferedReader br new BufferedReadernew FileReaderdictionarytxt
String line;
while line brreadLine null
String parts line.split; Split into word and definition
if partslength
dictionary.putpartstrimtoLowerCase partstrim;
catch IOException e
System.err.printlnError reading dictionary file.";
Method to load synonyms from file
private static void loadSynonymsMap synonyms
try BufferedReader br new BufferedReadernew FileReadersynonymstxt
String line;
while line brreadLine null
String parts line.split; Split into word and commaseparated synonyms
if partslength
String word partstrimtoLowerCase;
String synonymArray partssplit;
List synonymList new ArrayList;
for String synonym : synonymArray
synonymList.addsynonymtrim;
synonyms.putword synonymList;
catch IOException e
System.err.printlnError reading synonyms file.";
no changes to the code, but I need them to display the definitions of the synonyms where they are displayed, in Java btw
happy,joyful,content
sad,unhappy,miserable
fast,quick,rapid
slow,sluggish,delayed
big,large,huge
small,tiny,minute
strong,powerful,sturdy
weak,fragile,brittle
intelligent,smart,clever
dumb,stupid,foolish
beautiful,pretty,lovely
ugly,unattractive, hideous
hard,difficult, challenging
easy,simple,effortless
Test Case
Enter a word to look up: backslash
complex
Word not found in the dictionary: complex backslash mathrmn
Test Case
Enter a word to look up: backslash mathrmn
easy
Definition of easy: achieved without great effort; presenting few difficulties.
Synonyms for easy: backslash mathrmn
simple: easily understood or done; presenting no difficulty.
effortless: requiring no physical or mental exertion.
Test Case
Enter a word to look up: square mathrmn
slow
Definition of slow: moving or operating, or designed to do so only at a low speed. square mathrmn
Synonyms for slow: backslash
sluggish: slowmoving or inactive.
delayed: occurring or done too late.
Test Case
Enter a word to look up: backslash mathrmn
large
Definition of large: of considerable or relatively great size, extent, or capacity. square mathrmn
No synonyms found for large backslash n
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
