PBO - Tugas 5 - Aplikasi Support System
- Dapatkan link
- X
- Aplikasi Lainnya
TUGAS 5 - support system
Nama : Kevin Ashil
NRP : 05111740000178
Kelas : PBO - B
NRP : 05111740000178
Kelas : PBO - B
Pada minggu ke-5 mahasiswa ditugaskan untuk membuat program Technical Support yang dapat menjawab input user dan menjawabnya seperti pada TechSupport biasanya. Berikut merupakan program tersebut:
SupportSystem:
DATA HOSTED WITH ♥ BY PASTEBIN.COM - DOWNLOAD RAW - SEE ORIGINAL
- /**
- * This class implements a technical support system. It is
- * the top-level class in this project. The support system
- * communicates via text input/output in the text terminal.
- * This class uses an object of class InputReader to read
- * input from the user and an object of class Responder to
- * generate responses.
- * It contains a loop that repeatedly reads input and
- * generates output until the user wants to leave.
- *
- * @author Kevin Ashil
- * @version 0.1 (24 November 2020)
- */
- import java.util.*;
- public class SupportSystem
- {
- private InputReader reader;
- private Responder responder;
- /**
- * Creates a technical support system.
- */
- public SupportSystem()
- {
- reader = new InputReader();
- responder = new Responder();
- }
- /**
- * Start the technical support system. This will print a
- * welcome message and enter into a dialog with the user,
- * until the user ends the dialog.
- */
- public void start()
- {
- boolean finished = false;
- printWelcome();
- while(!finished) {
- HashSet<String> input = reader.getInput();
- if(input.contains("bye")) {
- finished = true;
- }else {
- String response = responder.generateResponse(input);
- System.out.println(response);
- }
- }
- printGoodbye();
- }
- /**
- * Print a welcome message to the screen.
- */
- private void printWelcome()
- {
- System.out.println(
- "Welcome to the Technical Support System.");
- System.out.println();
- System.out.println("Please tell us about your problem.");
- System.out.println(
- "We will assist you with any problem you might have.");
- System.out.println(
- "Please type 'bye' to exit our system.");
- }
- /**
- * Print a good-bye message to the screen.
- */
- private void printGoodbye()
- {
- System.out.println("Nice talking to you. Goodbye");
- }
- }
InputReader:
DATA HOSTED WITH ♥ BY PASTEBIN.COM - DOWNLOAD RAW - SEE ORIGINAL
- /**
- * The InputReader class is use for reading the input entry
- *
- * @author Kevin Ashil
- * @version 0.1 (24 November 2020)
- */
- import java.util.*;
- public class InputReader
- {
- private Scanner reader;
- public InputReader()
- {
- reader = new Scanner(System.in);
- }
- /**
- * Read user input
- */
- public HashSet<String> getInput()
- {
- System.out.print(">> ");
- String inputLine = reader.nextLine().trim().toLowerCase();
- String[] wordArray = inputLine.split(" ");
- HashSet<String> words = new HashSet<String>();
- for(String word : wordArray)
- {
- words.add(word);
- }
- return words;
- }
- }
Responder:
DATA HOSTED WITH ♥ BY PASTEBIN.COM - DOWNLOAD RAW - SEE ORIGINAL
- /**
- * The responder class represents a response generator object.
- * It is used to generate an automatic response to an input string.
- *
- * @author Kevin Ashil
- * @version 0.1 (24 November 2020)
- */
- import java.util.*;
- public class Responder
- {
- private Random randomGenerator;
- private ArrayList<String> defaultResponses;
- private HashMap<String, String>responseMap;
- /**
- * Construct a Responder - nothing to do
- */
- public Responder()
- {
- randomGenerator = new Random();
- defaultResponses = new ArrayList<String>();
- responseMap = new HashMap<String, String>();
- fillResponses();
- fillDefaultResponses();
- }
- /**
- * Generate a response.
- * @return A string that should be displayed as the
- * response
- */
- public String generateResponse(HashSet<String> words)
- {
- for(String word:words)
- {
- String response = responseMap.get(word);
- if(response != null)
- {
- return response;
- }
- }
- return pickDefaultResponse();
- }
- /**
- * 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()
- {
- responseMap.put("hey", "Hello, How can i help you?");
- responseMap.put("hello", "Hi there! " + "How can i help?");
- responseMap.put("error", "I am sorry to hear that"
- + ", We are trying to fix the problem as soon as possible");
- responseMap.put("nice", "Thank you for your compliment");
- responseMap.put("issue", "I am sorry for your inconvenience"
- + ", What is the issue?");
- responseMap.put("thanks", "It's my pleasure!");
- }
- private void fillDefaultResponses()
- {
- defaultResponses.add("Sorry I can't understand.");
- defaultResponses.add("Please try again.");
- }
- private String pickDefaultResponse()
- {
- int index = randomGenerator.nextInt(defaultResponses.size());
- return defaultResponses.get(index);
- }
- }
Berikut program yang dijalankan dengan beberapa Test Case:
- Dapatkan link
- X
- Aplikasi Lainnya
Komentar
Posting Komentar