document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. import java.util.*;
  2. /**
  3.  * The responder class represents a response-generator object.
  4.  * It is used to generate an automatic response to an input string.
  5.  *
  6.  * @author      Muhammad Bagus Istighfar
  7.  * @version     0.1 - 11 November 2020
  8.  */
  9. public class Responder
  10. {
  11.         private Random randomGenerator;
  12.         private ArrayList<String> defaultResponses;
  13.         private HashMap<String, String> responseMap;
  14.         /**
  15.          * Create a responder.
  16.          */
  17.         public Responder()
  18.         {
  19.             defaultResponses = new ArrayList<String>();
  20.             responseMap = new HashMap<String, String>();
  21.             fillResponses();
  22.             fillDefaultResponses();
  23.             randomGenerator = new Random();
  24.         }
  25.         /**
  26.          * Generate a response.
  27.          * @return      A string that should be displayed as the response.
  28.          */
  29.         public String generateResponse(HashSet<String> words)
  30.         {
  31.             for(String word : words)
  32.             {
  33.                 String response = responseMap.get(word);
  34.                 if(response != null)
  35.                 {
  36.                     return response;
  37.                 }
  38.             }
  39.             return pickDefaultResponse();
  40.         }
  41.         /**
  42.          * Build up a list of default responses from which we can pick one
  43.          * if we don\'t know what else to say.
  44.          */
  45.         private void fillResponses()
  46.         {
  47.             responseMap.put("halo", "Haloo!!!" + "Bagaimana kabarmu?");
  48.             responseMap.put("buruk", "Apakah kamu sakit? :(");
  49.             responseMap.put("sedih", "Semoga harimu lekas membaik ya!" + "Jadikan harimu sebagai pembelajaran");
  50.             responseMap.put("baik", "Wawww, aku juga ikut senang.");
  51.             responseMap.put("tidak", "oh, okee.");
  52.             responseMap.put("kamu", "Aku ChatSkuy, yang akan menemani hari - harimu");
  53.             responseMap.put("kasih", "Sudah menjadi tugasku");
  54.         }
  55.        
  56.         private void fillDefaultResponses()
  57.         {
  58.             defaultResponses.add("Maaf saya tidak mengerti ");
  59.             defaultResponses.add("Coba lagi");
  60.         }
  61.        
  62.         private String pickDefaultResponse()
  63.         {
  64.             int index = randomGenerator.nextInt(defaultResponses.size());
  65.             return defaultResponses.get(index);
  66.         }
  67.    
  68. }
');