Problem

Consider the following Thesaurus class: class Thesaurus { //Returns all synonyms o...

Consider the following Thesaurus class:

class Thesaurus {

//Returns all synonyms of the word as a Set

//Returns null if there is no such word

public java.util.Set<String> get (String word){...}

//Returns all key words in this thesaurus as a Set

//returns an empty set if there are no keys (if you

//don't do anything, default behavior of the

//underlying JCF class will handle it)

public java.util.Set<String> keys( ){...}

//Adds 'synonym' to the synonym set of 'word'

//Pay close attention to this method.

public void put (String word, String synonym){...}

}

The get method returns a set of all synonyms of a given word. The keys method returns all key words in the thesaurus. The put method adds a new synonym to the given word. Make sure to handle the cases when the word already has a synonym list and when the word is added for the first time. Using this Thesaurus class, we can write, for example, this program:

class SampleMain {

public static void main(String[] args) {

Thesaurus t = new Thesaurus();

t.put("fast", "speedy");

t.put("fast", "swift");

t.put("slow", "sluggish");

Set<String> synonyms = t.get("fast");

System.out.println(synonyms);

System.out.println(t.keys());

}

}

When the sample program is executed, the output will be

Implement the Thesaurus class, using one of the Map classes. The key is the word, and the value is the set of synonyms of this word.

Step-by-Step Solution

Request Professional Solution

Request Solution!

We need at least 10 more requests to produce the solution.

0 / 10 have requested this problem solution

The more requests, the faster the answer.

Request! (Login Required)


All students who have requested the solution will be notified once they are available.
Add your Solution
Textbook Solutions and Answers Search
Solutions For Problems in Chapter 10