document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1.  
  2. /**
  3.  * Response output to the System
  4.  *
  5.  * @author (prabu)
  6.  * @version (2020/11/9)
  7.  */
  8. import java.util.HashMap;
  9. import java.util.HashSet;
  10. import java.util.ArrayList;
  11. import java.util.Random;
  12. import java.time.LocalTime;
  13.  
  14. public class Responder
  15. {
  16.     private HashMap<String, String> responseMap;
  17.     private Random randomGenerator;
  18.     private ArrayList<String> responses, faq, greetings;
  19.    
  20.     /**
  21.      * Constructor for the Responder based on the user input
  22.      *
  23.      */
  24.     public Responder()
  25.     {
  26.         randomGenerator = new Random();
  27.         LocalTime time = LocalTime.now();
  28.         greetings = new ArrayList<String>();
  29.         faq = new ArrayList<String>();
  30.         responses = new ArrayList<String>();
  31.         responseMap = new HashMap<String, String>();
  32.         fillGreetings(time.getHour());
  33.         fillFAQ();
  34.         fillResponseMap();
  35.         fillResponses();
  36.     }
  37.    
  38.     /**
  39.      * Enter all the greetings into the greetings ArrayList
  40.      */
  41.     private void fillGreetings(int h)
  42.     {
  43.         if(h >= 3 && h < 11)
  44.         {
  45.             greetings.add("Good Morning. ");
  46.             greetings.add("Morning! ");
  47.         }
  48.         else if(h >= 11 && h < 15)
  49.         {
  50.             greetings.add("Good Afternoon. ");
  51.             greetings.add("Salutations in the afternoon, good man/woman! ");
  52.             greetings.add("Afternoon, Sir/Mam! ");
  53.         }
  54.         else if(h >= 15 && h < 19)
  55.         {
  56.             greetings.add("Good Evening, Costumer. ");
  57.             greetings.add("Evening. ");
  58.         }
  59.         else
  60.         {
  61.             greetings.add("Greetings. ");
  62.             greetings.add("Hello and Welcome! ");
  63.             greetings.add("Nights has fallen, but we still will try our best! ");
  64.         }
  65.     }
  66.    
  67.     /**
  68.      * Enter all the respones for the FAQ
  69.      */
  70.     private void fillFAQ()
  71.     {
  72.         faq.add("Try upgrading your program to the latest stable version "+
  73.         "or/and try upgrading your processor too.");
  74.         faq.add("Try end task by using task manager or restart your "+
  75.         "computer.");
  76.         faq.add("Try upgrading your processor.");
  77.     }
  78.    
  79.     /**
  80.      * Enter all the default response into the response ArrayList
  81.      */
  82.     private void fillResponses()
  83.     {
  84.         responses.add("Interesting. I need a bit more information than that.");
  85.         responses.add("No other costumer has ever complained about this before.\\n"+
  86.         "Can you provide more information about your problems?");
  87.         responses.add("That sounds odd. Could you elaborate on that?");
  88.         responses.add("Have you checked that you do not have a dll "+
  89.         "conflict?");
  90.         responses.add("Your description is a bit wishy-washy.\\n"+
  91.         "Have you got an expert there with you that could describe this "+
  92.         "more precisely?");
  93.         responses.add("Allright. Have you considered upgrading your processor?\\n"+
  94.         "It might solve all your problems.");
  95.     }
  96.    
  97.     /**
  98.      * Enter all the known keywords and their associated responses into our
  99.      * response map.
  100.      */
  101.     private void fillResponseMap()
  102.     {
  103.         responseMap.put("slow",
  104.         "I think this has to do with your hardware.\\n"+
  105.         "Upgrading your processor should solve all your performance problems.\\n"+
  106.         "Have you got problem with our software?");
  107.         responseMap.put("bug",
  108.         "All software has their own bugs.\\n" +
  109.         "Our software engineers are working very had to solve them.\\n"+
  110.         "Can you describe the problem a bit further?");
  111.         responseMap.put("expensive",
  112.         "The cost of each product is based on the features and what they offers\\n"+
  113.         "Have you really looked around and compared our features?");
  114.     }
  115.    
  116.     /**
  117.      * Generate a response based on the user input
  118.      *
  119.      * @param   HashSet of words from the user input
  120.      * @return  Strings of responses based on the user input
  121.      */
  122.     public String generateResponse(HashSet<String>words)
  123.     {
  124.         for(String word: words)
  125.         {
  126.             String response = responseMap.get(word);
  127.             responseMap.get(word);
  128.             if(response != null)
  129.             {
  130.                 return response;
  131.             }
  132.         }
  133.         // If we get here, none of the words from the input line was
  134.         // recognize. In this case, we pick one of our default responses.
  135.         return generateResponse();
  136.     }
  137.    
  138.     /**
  139.      * Generate a default response when there\'s no more valid response that
  140.      * corelate with the responseMap
  141.      *
  142.      * @return String of response
  143.      */
  144.     private String generateResponse()
  145.     {
  146.         // Pick a random number for the index in the default response list.
  147.         // The number will be between 0 (includes) and the size of the
  148.         // list (exclusives).
  149.         int index = randomGenerator.nextInt(responses.size());
  150.         return responses.get(index);
  151.     }
  152.    
  153.     /**
  154.      * Return the FAQ response corresponding to the user input option
  155.      *
  156.      * @param   The inputOption that determines the correct response
  157.      * @return  Strings of response based on the inputOption
  158.      */
  159.     public String getFAQ(int opt)
  160.     {
  161.         return faq.get(opt-1);
  162.     }
  163.    
  164.     /**
  165.      * Generate greetings response depends on the hour of the day
  166.      *
  167.      * @return  Strings of greetings.
  168.      */
  169.     public String generateGreeting()
  170.     {
  171.         int index = randomGenerator.nextInt(greetings.size());
  172.         return greetings.get(index);
  173.     }
  174. }
  175.  
');