Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class Responder
- {
- private Random randomGenerator;
- private ArrayList<String> responses;
- private HashMap<String, String> responseMap;
- public Responder()
- {
- randomGenerator = new Random();
- responses = new ArrayList<String>();
- responseMap = new HashMap<String, String>();
- fillResponses();
- fillResponseMap();
- }
- public String generateResponse(HashSet<String> words)
- {
- for(String word:words)
- {
- String response=responseMap.get(word);
- if(response!=null)
- {
- return response;
- }
- }
- int index = randomGenerator.nextInt(responses.size());
- return responses.get(index);
- }
- private void fillResponses()
- {
- responses.add("Sorry, i dont understand you");
- responses.add("Please try another word");
- }
- private void fillResponseMap()
- {
- responseMap.put("problem", "Can you describe more about the problem?");
- responseMap.put("bug", "What kind of bug?");
- responseMap.put("error", "What kind of error?");
- responseMap.put("stop", "You can restart the program");
- responseMap.put("thanks", "You're Welcome");
- }
- }
Add Comment
Please, Sign In to add comment