- import java.util.ArrayList;
- import java.util.Random;
- import java.util.HashMap;
- /**
- * The responder class represents a response generator object. It is
- * used to generate an automatic response.
- * This is the second version of this class. This time, we generate
- * some random behavior by randomly selecting a phrase from a predefined
- * list of responses.
- *
- * @author Michael Kolling and David J. Barnes
- * @version 0.2
- */
- public class Responder
- {
- private Random randomGenerator;
- private ArrayList<String> responses;
- public HashMap<String,String> smartResponder;
- /**
- * Construct a Responder
- */
- public Responder()
- {
- randomGenerator = new Random();
- responses = new ArrayList<String>();
- fillResponses();
- smartResponder = new HashMap <String,String>();
- fillSmartResponder();
- }
- /**
- * Generate a response.
- *
- * @return A string that should be displayed as the response
- */
- public String generateResponse()
- {
- // Pick a random number for the index in the default response
- // list. The number will be between 0 (inclusive) and the size
- // of the list (exclusive).
- int index = randomGenerator.nextInt(responses.size());
- return responses.get(index);
- }
- private void fillSmartResponder()
- {
- smartResponder.put("slow",
- "I think this has to do with your hardware. \n" +
- "Upgrading your processor should solve all \n" +
- "performance problems. Have you got a problem with \n" +
- "our software?");
- smartResponder.put("bug",
- "Well, you know, all software has some bugs. But \n" +
- "our software engineers are working very hard to \n" +
- "fix them. Can you describe the problem a bit \n" +
- "further?");
- smartResponder.put("expensive",
- "The cost of our product is quite competitive. \n" +
- "Have you looked around and really compared \n" +
- "our features?");
- }
- /**
- * Build up a list of default responses from which we can pick one
- * if we don't know what else to say.
- */
- private void fillResponses()
- {
- responses.add("That sounds odd. Could you describe that problem in more detail?");
- responses.add("No other customer has ever complained about this before. \n" +
- "What is your system configuration?");
- responses.add("That sounds interesting. Tell me more...");
- responses.add("I need a bit more information on that.");
- responses.add("Have you checked that you do not have a dll conflict?");
- responses.add("That is explained in the manual. Have you read the manual?");
- responses.add("Your description is a bit wishy-washy. Have you got an expert\n" +
- "there with you who could describe this more precisely?");
- responses.add("That's not a bug, it's a feature!");
- responses.add("Could you elaborate on that?");
- }
- }