Technical Support System

     Technical Support System merupakan suatu layanan yang berfungsi untuk membantu user atau mengatasi masalah yang dialami user. Program di bawah ini akan menjawab pertanyaan dari user. Jadi, ketika user menginputkan sesuatu, maka sistem akan merespon user.

    Program Technical Support System terdiri dari beberapa kelas, diantaranya sebagai berikut :

1. SupportSystem   : Kelas utama dari program. 

2. InputReader        : Kelas ini akan menerima input dari user, yaitu berupa pertanyaan

3. Responder           : Kelas ini  akan memberi respon atas input user, yaitu berupa jawaban yang sesuai dengan pertanyaan user


1. Class SupportSystem

    Kelas ini merupakan utama dari program. Kelas ini menggunakan objek dari kelas InputReader untuk membaca input user dan juga objek dari kelas Responder untuk merespon user.

  1. import java.util.*;
  2. /**
  3. * @author Sabrina Lydia S
  4. * @version 15/11/20
  5. */
  6. public class SupportSystem
  7. {
  8. private InputReader reader;
  9. private Responder responder;
  10. /**
  11. * Creates a technical SupportSystem
  12. */
  13. public SupportSystem()
  14. {
  15. reader = new InputReader();
  16. responder = new Responder();
  17. }
  18. /**
  19. * Start the technical support system. This will print a
  20. * welcome message and enter into a dialog with the user,
  21. * until the user ends the dialog.
  22. */
  23.  
  24. public void start()
  25. {
  26. boolean finished = false;
  27. printWelcome();
  28. while(!finished) {
  29. HashSet<String> input = reader.getInput();
  30. if(input.contains("bye")) {
  31. finished = true;
  32. }
  33. else {
  34. String response = responder.generateResponse(input);
  35. System.out.println(response);
  36. }
  37. }
  38. printGoodbye();
  39. }
  40. //Print welcome message to the screen
  41. private void printWelcome()
  42. {
  43. System.out.println("Welcome to PBO Technical Support System.");
  44. System.out.println();
  45. System.out.println("Please tell us about your problem.");
  46. System.out.println("We will assist you with any problem you might have.");
  47. System.out.println("Please type 'bye' to exit our system.");
  48. }
  49. //Print goodbye message to the screen
  50. private void printGoodbye()
  51. {
  52. System.out.println("It was nice talking to you, See you again");
  53. }
  54. }

2. Class InputReader

Kelas ini akan menerima input dari user, yaitu berupa teks, dan membaca teks tersebut.

  1. import java.util.Scanner;
  2. import java.util.HashSet;
  3. /**
  4. * @author Sabrina Lydia S
  5. * @version 15/11/20
  6. */
  7.  
  8. public class InputReader
  9. {
  10. private Scanner reader;
  11. /**
  12. * Constructor for objects of class InputReader
  13. * to read input text from user public InputReader()
  14. */
  15. public InputReader()
  16. {
  17. reader = new Scanner(System.in);
  18. }
  19. /**
  20. * Read a line of text from standard input (the text
  21. * terminal), and return it as a set of words.
  22. *
  23. * @return A set of Strings, where each String is one of the
  24. * words typed by the user
  25. */
  26. public HashSet<String> getInput()
  27. {
  28. System.out.print("> "); // print prompt
  29. String inputLine = reader.nextLine().trim().toLowerCase();
  30. String[] wordArray = inputLine.split(" ");
  31. // add words from array into hashset
  32. HashSet<String> words = new HashSet<>();
  33. for(String word : wordArray) {
  34. words.add(word);
  35. }
  36. return words;
  37. }
  38. }

3. Class Responder

Kelas ini  akan memberi respon atas input user, yaitu berupa jawaban yang sesuai dengan pertanyaan user.

  1. import java.util.HashMap;
  2. import java.util.HashSet;
  3. import java.util.ArrayList;
  4. import java.util.Iterator;
  5. import java.util.Random;
  6. /**
  7. * @author Sabrina Lydia S
  8. * @version 15/11/20
  9. */
  10.  
  11. public class Responder
  12. {
  13. //Default response used for unrecognized input
  14. private ArrayList<String> defaultResponses;
  15. private Random randomGenerator;
  16. // Mapping index/key to response
  17. private HashMap<String, String> responseMap;
  18. /**
  19. * Constructor for objects of class Responder
  20. */
  21. public Responder()
  22. {
  23. responseMap = new HashMap<String, String>();
  24. defaultResponses = new ArrayList<String>();
  25. fillResponseMap();
  26. fillDefaultResponses();
  27. randomGenerator = new Random();
  28. }
  29. /**
  30. * Generate a response from one set of input words given.
  31. *
  32. * @param words A set of words given by the user
  33. * @return String that should be displayed as a response
  34. */
  35. public String generateResponse(HashSet<String> words)
  36. {
  37. for(String word : words)
  38. {
  39. String response = responseMap.get(word);
  40. if(response != null)
  41. {
  42. return response;
  43. }
  44. }
  45. // If we get here, none of the words from the input line was
  46. // recognized. In this case, we pick one of our default responses.
  47. return pickDefaultResponse();
  48. }
  49. /**
  50. * Enter all the known keywords and their associated responses
  51. * into our response map.
  52. */
  53. private void fillResponseMap()
  54. {
  55. responseMap.put("hello", "hello.");
  56.  
  57. responseMap.put("hi", "hi.");
  58.  
  59. responseMap.put("problem",
  60. "Could you describe \n" +
  61. "that problem in more detail?");
  62.  
  63. responseMap.put("slow",
  64. "I think this has to do with your hardware. \n" +
  65. "Upgrading your processor should solve all " +
  66. "performance problems. \n" +
  67. "Have you got a problem with our software?");
  68.  
  69. responseMap.put("bug",
  70. "Well, you know, all software has some bugs. \n" +
  71. "But our software engineers are working very " +
  72. "hard to fix them. \n" +
  73. "Can you describe the problem a bit further?");
  74.  
  75. responseMap.put("expensive",
  76. "The cost of our product is quite competitive. \n" +
  77. "Have you looked around and " +
  78. "really compared our features?");
  79.  
  80. responseMap.put("windows",
  81. "That can be happened whether you use unoriginal windows \n" +
  82. "or you need to do further Update");
  83.  
  84. responseMap.put("how are you", "I'm doing fine!");
  85.  
  86. responseMap.put ("ok", "Anything else you wish to ask?");
  87.  
  88. responseMap.put("",
  89. "I don't quite understand about what you said. \n" +
  90. "Please try to ask me for other entry.");
  91. }
  92. /**
  93. * Build up a list of default responses from which we can pick one
  94. * if we don't know what else to say.
  95. */
  96. private void fillDefaultResponses()
  97. {
  98. defaultResponses.add("That sounds odd. Please be more specific");
  99. defaultResponses.add("I'm sorry, I didn't understand...");
  100. }
  101. /**
  102. * Randomly select and return one of the default responses.
  103. * @return A random default response
  104. */
  105. private String pickDefaultResponse()
  106. {
  107. // Pick a random number for the index in the default response list.
  108. // The number will be between 0 (inclusive) and the size of the list (exclusive).
  109. int index = randomGenerator.nextInt(defaultResponses.size());
  110. return defaultResponses.get(index);
  111. }
  112. }

Implementasi



Komentar

Postingan populer dari blog ini

Ticket Machine

ETS PWEB-A

Tugas 10 PBKK