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 main(String[] args){
// Initialize maps for dictionary and synonyms
Map dictionary = new HashMap>();
Map> synonyms = new HashMap>();
// Load data from files
loadDictionary(dictionary);
loadSynonyms(synonyms);
// Prompt user for input
Scanner scanner = new Scanner(System.in);
System.out.println("Enter a word to look up:");
String inputWord = scanner.nextLine().trim().toLowerCase();
// Search for the word in dictionary and synonyms
if (dictionary.containsKey(inputWord)){
System.out.println("Definition of "+ inputWord +": "+ dictionary.get(inputWord));
// Check for synonyms
if (synonyms.containsKey(inputWord)){
System.out.println("Synonyms for "+ inputWord +":");
for (String synonym : synonyms.get(inputWord)){
System.out.println("-"+ synonym +": ");
}
} else {
System.out.println("No synonyms found for "+ inputWord);
}
} else {
System.out.println("Word not found in the dictionary: "+ inputWord);
}
}
// Method to load dictionary from file
private static void loadDictionary(Map dictionary){
try (BufferedReader br = new BufferedReader(new FileReader("dictionary.txt"))){
String line;
while ((line = br.readLine())!= null){
String[] parts = line.split(",",2); // Split into word and definition
if (parts.length ==2){
dictionary.put(parts[0].trim().toLowerCase(), parts[1].trim());
}
}
} catch (IOException e){
System.err.println("Error reading dictionary file.");
}
}
// Method to load synonyms from file
private static void loadSynonyms(Map> synonyms){
try (BufferedReader br = new BufferedReader(new FileReader("synonyms.txt"))){
String line;
while ((line = br.readLine())!= null){
String[] parts = line.split(",",2); // Split into word and comma-separated synonyms
if (parts.length ==2){
String word = parts[0].trim().toLowerCase();
String[] synonymArray = parts[1].split(",");
List synonymList = new ArrayList>();
for (String synonym : synonymArray){
synonymList.add(synonym.trim());
}
synonyms.put(word, synonymList);
}
}
} catch (IOException e){
System.err.println("Error 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 5
Enter a word to look up: \(\backslash \).
complex
Word not found in the dictionary: complex \(\backslash \mathrm{n}\)
Test Case 6
Enter a word to look up: \(\backslash \mathrm{n}\)
easy
Definition of easy: achieved without great effort; presenting few difficulties.
Synonyms for easy: \(\backslash \mathrm{n}\)
- simple: easily understood or done; presenting no difficulty.
- effortless: requiring no physical or mental exertion.
Test Case 7
Enter a word to look up: \(\square \mathrm{n}\)
slow
Definition of slow: moving or operating, or designed to do so, only at a low speed. \(\square \mathrm{n}\)
Synonyms for slow: \(\backslash \).
- sluggish: slow-moving or inactive.
- delayed: occurring or done too late.
Test Case 8
Enter a word to look up: \(\backslash \mathrm{n}\)
large
Definition of large: of considerable or relatively great size, extent, or capacity. \(\square \mathrm{n}\)
No synonyms found for large \(\backslash n \)
import java.io . * ; import java.util. * ; public

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!