How JustAnswer Works:

  • Ask an Expert
    Experts are full of valuable knowledge and are ready to help with any question. Credentials confirmed by a Fortune 500 verification firm.
  • Get a Professional Answer
    Via email, text message, or notification as you wait on our site.
    Ask follow up questions if you need to.
  • 100% Satisfaction Guarantee
    Rate the answer you receive.

Ask Chris Baxter Your Own Question

Chris Baxter
Chris Baxter, Programming Tutor
Category: Programming
Satisfied Customers: 243
Experience:  Completed BSIT concentration Software Engineering, tutored other students and classmates in Java and VB.net, C++, and Obj C.
68869132
Type Your Programming Question Here...
Chris Baxter is online now
A new question is answered every 9 seconds

I'm programming a chatbot in Java. So far I've got it to

Customer Question

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 [blank space] in file responses.txt...... What is it I need to change?
public HashMap readAMap(String responses)
{
HashMap 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,
Submitted: 12 months ago.
Category: Programming
Expert:  ATLPROG replied 12 months ago.

Hello by when you need this

Expert:  ATLPROG replied 12 months ago.

Please upload what you got on wikiaend.com including Java code and requirements and post file id here

Customer: replied 12 months ago.
I have 45 minutes, do you think you can help in that time?
Expert:  ATLPROG replied 12 months ago.

Sorry thats too less time will opt out for others

Expert:  Chris Baxter replied 12 months ago.

I am assuming the words in the line to be read are not given any space before them...

so the problem is code...

public HashMap readAMap(String responses) { HashMap map = new HashMap(); try (BufferedReader reader = new BufferedReader(new FileReader << Where is the file reader object declaration?

ex:

FileReader in = new FileReader("C:/test.txt"); BufferedReader br = new BufferedReader(in);

Expert:  Chris Baxter replied 12 months ago.

It seems you have called an object creation without defining the object name for it, so errors and does not create the part of the reader that populated the check object for responses, thus the null error