Hello,
I'm programming a chatbot in Java. So far I've got it to read the default responses from a txt file (in the form of an ArrayList) but I can't get it to read my main response file. It prints out saying Blank response for... What is it I need to change?
public HashMap<String, String> readAMap(String responses)
{
HashMap<String, String> map = new HashMap<>();
try (BufferedReader reader =
new BufferedReader(new FileReader("responses.txt"))) {
String word;
word =reader.readLine();
while(word != null) {
String response = reader.readLine();
if(response != null) {
response = response.trim();
if(response.length() != 0) {
map.put(word, response);
}
else {
System.out.println("Blank response for " +
word + " in file " +
responses);
}
}
else {
System.out.println("Missing response for " +
word + " in file " +
responses);
}
word = reader.readLine();
}
}
catch(IOException e) {
System.out.println("Problem reading file: " + responses +
" in readAMap");
}
return map;
}
After this I need to create a trainer mode which can be selected instead of the user mode. The idea of training mode is that a trainer should be able to add new word : response pairs
to the system.
There are two parts to this functionality:
• The trainer can add a word and the associated response.
• The program shows the trainer previously saved user input that had no matching
response and requests one or more word:response pairs that could be used to
match that same input on future runs in user mode.
I'm looking for help with the above and help with understanding the concepts of cohesion, coupling and refactoring as they apply to this assignment. I hope someone can help.
Kind regards,