responseMap. (For example, there are identical responses for "crash" and "crashes" in the map.) It will also give you a chance to get more familiar with maps, and to explore the TechSupport project in more detail.
> SupportSystem s = new SupportSystem(); > s.start(); Welcome to the DodgySoft Technical Support System. Please tell us about your problem. We will assist you with any problem you might have. Please type 'bye' to exit our system. > I think your software is buggy! Well, you know, all software has some bugs. But our software engineers are working very hard to fix them. Can you describe the problem a bit further? > It crashes when I try to open a file. Well, it never crashes on our system. It must have something to do with your system. Tell me more about your configuration. > It didn't used to crash. Well, it never crashes on our system. It must have something to do with your system. Tell me more about your configuration. > No thanks -- this is pointless. Bye. Nice talking to you. Bye...
fillResponseMap method in the Responder class shows that there are duplicate entries — one for each of the variations. We could simplify the Responder class, and provide better output, if we took the user's input words and mapped them to a root synonym before consulting the responseMap. For example, "crashes", "quits", and "dies" might all map to "crash". Then we'd only need one entry in the responseMap — an entry for the root synonym "crash". We'll complete a new class to do the synonym mapping, then integrate it into the project.
I've written most of the SynonymMapper class for you. You just need to finish the body of the rootSynonym method. Finish the method now: Write code that checks for the input word in our synonym map. If we find it, return the corresponding root synonym. If we don't find the input word in the map, just return the original word. You can test your SynonymMapper class by itself when you're finished:
> SynonymMapper sm = new SynonymMapper();
> sm.rootSynonym("dies")
"crash" (String)
> sm.rootSynonym("quits")
"crash" (String)
> sm.rootSynonym("crashes")
"crash" (String)
> sm.rootSynonym("aardvark")
"aardvark" (String)
generateResponse method in the Responder class and make sure you understand how it works: It looks through each of the words in the input set, hoping to find a word it recognizes. If it finds a known word it returns the corresponding output message, otherwise it selects a default response randomly. Modify this code so that it maps each word from the set to its root synonym, then looks for the synonym in responseMap. Before testing, remove the lines in fillResponseMap that add entries for "crashes" and "buggy" — we don't need them anymore. Compile and run the system:
> SupportSystem s = new SupportSystem(); > s.start(); Welcome to the DodgySoft Technical Support System. Please tell us about your problem. We will assist you with any problem you might have. Please type 'bye' to exit our system. > It just quits! Well, it never crashes on our system. It must have something to do with your system. Tell me more about your configuration. > Well it crashes on MY system! Well, it never crashes on our system. It must have something to do with your system. Tell me more about your configuration. > When I open a file, the program dies. Well, it never crashes on our system. It must have something to do with your system. Tell me more about your configuration. > No! Could you elaborate on that? > bye Nice talking to you. Bye...
toString method to the SynonymMapper class that lists all of the known mappings as part of the returned string.
generateResponse stops and uses the first "meaningful" word from the input set. Modify the method so that it selects input words randomly when the set contains more than one meaningful word. (You could build an ArrayList containing all meaningful words from the set, then choose one.)
static. Did the output change? Why or why not?