Question: 1) Add more word/response mappings to your application. For example, add more social skills e.g. add a response to if the user greets the system.
1) Add more word/response mappings to your application. For example, add more social skills e.g. add a response to if the user greets the system. (1M) 2) Ensure that the same default response is never repeated twice in a row. Hint: You'll have to create a member variable to be used in the method pickDefaultResponse() to remember the previous index. (1M) 3) Sometimes two words (or variations of a word) are mapped to the same response, e.g. it should not make a difference if the user uses the singular "bug" or the plural "bugs" or whether they say "crash" or "crashes". Deal with this by mapping synonyms or related expressions to the same string ID so that you do not need multiple entries in the response map for the same response. Hints: You will need to introduce a field synonymMap similar to responseMap. Make sure this new HashMap is initialized correctly in the constructor. Then change the generateResponse() method to also account for synonyms. public class InputReader { private Scanner reader; /** * Create a new InputReader that reads text from the text terminal. */ public InputReader() { reader = new Scanner(System.in); } /** * Read a line of text from standard input (the text terminal), * and return it as a set of words. * * @return A set of Strings, where each String is one of the words typed by the user */ public HashSet get Input() { COR System.out.print("> Il print prompt inputLine reader.nextLine(): trinos.ltoLowerCasell); String[] wordArray = inputline.split(" "); // split at spaces // add words from array into hashset HashSet words = new HashSet(); for(String word : wordArray) { words.add(word); } return words; } public class InputReader { private Scanner reader; /** * Create a new InputReader that reads text from the text terminal. */ public InputReader() { reader = new Scanner(System.in); } * /** * Read a line of text from standard input (the text terminal), * and return it as a set of words. * @return A set of Strings, where each String is one of the words typed by the user */ public HashSet getInput() { System.out.print("> // print prompt String inputLine = reader.nextLine().trim().toLowerCase(); String[] wordArray = inputline.split(""); // split at spaces // add words from array into hashset HashSet words = new HashSet(); for(String word : wordArray) { words.add(word); } return words; public class Responder { // Used to map key words to responses. private HashMap responseMap; // Default responses to use if we don't recognise a word. private ArrayList defaultResponses; private Random randomGenerator; /** * Construct a Responder */ public Responder() { responseMap = new HashMap(); defaultResponses = new ArrayList(); fillResponseMap(); fillDefaultResponses(); randomGenerator = new Random(); } /** * Generate a response from a given set of input words. * @param words A set of words entered by the user * @return A string that should be displayed as the response */ public String generateResponse (HashSet words) { for (String word words) { String response = responseMap.get(word); ifresnonse - 5 default responses what we say when 1/ we cannot think of anything else to say...) return pickDefaultResponse(); } 7** * Enter all the known keywords and their associated responses * into our response map. */ private void fillResponseMap { responseMap.put("crash", "Well, it never crashes on our system. It must have something " + "to do with your system. Tell me more about your configuration."); responseMap.put("slow", "I think this has to do with your hardware. Upgrading your processor " + "should solve all performance problems. Have you got a problem with " + "our software?"); responseMap.put("performance", "Performance was quite adequate in all our tests. Are you running " + "any other processes in the background?"); responseMap.put("bug", "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 " + 23:36 Student Done Responder "further?"); responseMap.put("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?"); responseMap.put("windows", "This is a known bug to do with the Windows operating system. Please " + "report it to Microsoft. There is nothing we can do about this."); responseMap.put("mac", "This is a known bug to do with the Mac operating system. Please " + "report it to Apple. There is nothing we can do about this."); responseMap.put("expensive", "The cost of our product is quite competitive. Have you looked around " + "and really compared our features?"); responseMap.put("installation", "The installation is really quite straight forward. We have tons of " + "Wizards that do all the work for you. Have you read the installation " + "instructions?"); responseMap.put("memory", "If you read the system requirements carefully, you will see that the " + "specified memory requirements are 1.5 giga byte. You really should " + upgrade your "further?"); responseMap.put("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?"); responseMap.put("windows", "This is a known bug to do with the Windows operating system. Please " + "report it to Microsoft. There is nothing we can do about this."); responseMap.put("mac", "This is a known bug to do with the Mac operating system. Please " + "report it to Apple. There is nothing we can do about this."); responseMap.put("expensive", "The cost of our product is quite competitive. Have you looked around " + "and really compared our features?"); responseMap.put("installation", "The installation is really quite straight forward. We have tons of " + "wizards that do all the work for you. Have you read the installation " + "instructions?"); responseMap.put("memory", "If you read the system requirements carefully, you will see that the " + "specified memory requirements are 1.5 giga byte. You really 23:36 Student Done Responder "instructions?"); responseMap.put("memory", "If you read the system requirements carefully, you will see that the " + "specified memory requirements are 1.5 giga byte. You really should " + "upgrade your memory. Anything else you want to know?"); responseMap.put("linux" "We take Linux support very seriously. But there are some problems. In" + "Most have to do with incompatible glibc versions. Can you be a bit " + "more precise?"); responseMap.put("bluej", "Ahhh, Blue), yes. We tried to buy out those guys long ago, but " + "they simply won't sell... Stubborn people they are. Nothing we can " + "do about it, I'm afraid."); /** * Build up a list of default responses from which we can pick one * if we don't know what else to say. */ private void fillDefaultResponses { defaultResponses.add("That sounds odd. Could you describe that problem in more detail?"); defaultResponses.add("No other customer has ever complained about this before. " + "What is your system configuration?"); defaultResponses.adThat sounds 23:36 Student Done Responder before. " + "What is your system configuration?"); defaultResponses.add("That sounds interesting. Tell me more..."); defaultResponses.add("I need a bit more information on that."); defaultResponses.add("Have you checked that you do not have a dll conflict?"); defaultResponses.add("That is explained in the manual. Have you read the manual?"); defaultResponses.add("Your description is a bit wishy-washy. Have you got an expert " + "there with you who could describe this more precisely?"); defaultResponses.add("That's not a bug, it's a feature!"); defaultResponses.add("Could you elaborate on that?"); } /** * Randomly select and return one of the default responses. * @return A random default response */ private String pickDefaultResponse) { // Pick a random number for the index in the default response list. // The number will be between (inclusive) and the size of the list (exclusive). int index = randomGenerator.nextInt(defaultResponses.si ze()); return defaultResponses.get(index); } } 23:36 Student Done Ringer public class Support System { private InputReader reader; private Responder responder; /** * Creates a technical support system. */ public Support System) reader = new InputReader(); responder = new Responder(); } * Start the technical support system. This will print a welcome message and enter * into a dialog with the user, until the user ends the dialog. */ public void start() { boolean finished = false; printWelcome(); while('finished) { HashSet input reader.getInput(); if(input.contains("bye")) { finished = true; else { String response = responder generateResponse (input); System.out.println(response); } } print Goodbye(); } /** * Print a TOTCOM message to the 23:36 Student Done Support System } print Goodbye(); } /** * Print a welcome message to the screen. */ private void printWelcome() { System.out.println("Welcome to the DodgySoft Technical Support System."); System.out.println(); System.out.println("Please tell us about your problem."); System.out.println("We will assist you with any problem you might have."); System.out.println("Please type 'bye' to exit our system."); } /** * Print a good-bye message to the screen. */ private void print Goodbye() { System.out.println("Nice talking to you. Bye..."); } public static void main( String[] args) { Support System system = new Support System();; system.start(); } }