Question: Complete exercise 14.47 on page 552 Submit the Responder.java file Responder.java file: import java.io.*; import java.nio.charset.Charset; import java.nio.file.*; import java.util.*; public class Responder{ //Default responses
Complete exercise 14.47 on page 552 Submit the Responder.java file

Responder.java file:
import java.io.*; import java.nio.charset.Charset; import java.nio.file.*; import java.util.*;
public class Responder{ //Default responses to use if we dont recognise a word private List DefaultResponses; //Tha name of the file containing the default responses private static final String FILE_OF_DEFAULT_RESPONSES = "default.txt";
/** *Build up a list of the default responses from which can be pick *if we dont know what else to say. **/ private void fillDefaultResponses(){ Charset charset = Charset.forName("US-ASCII"); Path path = Path.get(FILE_OF_DEFAULT_RESPONSES); try (BufferedReader reader = Files.newBufferReader(path, charset)){ String response = reader.readLine(); while(response != null){ defaultResponses.add(response); response = reader.readLine(); } } catch(FileNotFoundException e){ Sytem.err.printLn("A problem was encountered reading " + FILE_OF_DEFAULT_RESPONSES); } //Make sure we have at least one response. s if(defaultResponses.dize()==0){ DefaultResponses.add("Could you elaborate on that?"); } }
}
52 Chapter 14 Handling Errors Responses method. Using any text editor, change it contains an empty line between anyt work correctly again in reading in the responses from this file. Exercise 14.45 The file default.txt in the project folder of the t support-io project contains the default responses read in by the fi11D code 14.2 oursoth Reading inte ger data wit the content of this file so that scann Exercise 14.46 Change your code so that several lines of text found in th file not separated by an empty line are read as one single response. Change the default.txt file so that it contains some responses spanning multiple lines. Test. Exercise 14.47 Modify the Responder class of the tech-support-io project so that it reads the associations between keywords and responses from a text file, rather than initializing responseMap with strings written into the source code in the fil1ResponseMap method. You can use the fil1DefaultResponses method as a pattern, but you will need to make some changes to its logic, because there are two strings to be read for each entry rather than one-the keyword and the response. Try storing keywords and responses on alternating lines; keep the text of each response on a single line. You may assume that there will always be an even number of lines (i.e., no missing responses). 52 Chapter 14 Handling Errors Responses method. Using any text editor, change it contains an empty line between anyt work correctly again in reading in the responses from this file. Exercise 14.45 The file default.txt in the project folder of the t support-io project contains the default responses read in by the fi11D code 14.2 oursoth Reading inte ger data wit the content of this file so that scann Exercise 14.46 Change your code so that several lines of text found in th file not separated by an empty line are read as one single response. Change the default.txt file so that it contains some responses spanning multiple lines. Test. Exercise 14.47 Modify the Responder class of the tech-support-io project so that it reads the associations between keywords and responses from a text file, rather than initializing responseMap with strings written into the source code in the fil1ResponseMap method. You can use the fil1DefaultResponses method as a pattern, but you will need to make some changes to its logic, because there are two strings to be read for each entry rather than one-the keyword and the response. Try storing keywords and responses on alternating lines; keep the text of each response on a single line. You may assume that there will always be an even number of lines (i.e., no missing responses)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
