Sunday, October 7, 2018

PBO A: Membuat Tech Support/Support System

Nama; Muhammad Naufal Refadi
NRP: 05111740000097
Kelas: PBO-A

Ini adalah tugas untuk membuat Tech Support/Support System

a) SupportSystem
  /**   
  * Tech Support   
  * @author Muhammad Naufal Refadi   
  * @version 8 October 2018   
  */   
 import java.util.HashSet;  
 public class SupportSystem  
 {  
   private InputReader reader;  
   private Responder responder;  
   public SupportSystem(){  
     reader = new InputReader();  
     responder= new Responder();  
   }  
   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();  
         System.out.println(response);  
       }  
     }  
     printGoodbye();  
   }      
   private void printWelcome()  
     {  
      System.out.println("Welcome to the DodgySoft 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. Bye...");  
   }  
 }  

b) InputReader
 import java.util.HashSet;  
 import java.util.Scanner;  
 /**  
  * InputReader reads typed text input from the standard text terminal.   
  * The text typed by a user is then chopped into words, and a set of words   
  * is provided.  
  *   
  * @author   Michael Kolling and David J. Barnes  
  * @version  2008.03.30  
  */  
 public class InputReader  
 {  
   private Scanner reader;  
   /**  
    * Create a new InputReader that reads text from the text terminal.  
    */  
   public InputReader()  
   {  
     reader = new Scanner(System.in);  
   }  
   /**  
    * Read a line of text from standard input (the text terminal),  
    * and return it as a set of words.  
    *  
    * @return A set of Strings, where each String is one of the   
    *     words typed by the user  
    */  
   public HashSet<String> getInput()   
   {  
     System.out.print("> ");        // print prompt  
     String inputLine = reader.nextLine().trim().toLowerCase();  
     String[] wordArray = inputLine.split(" "); // split at spaces  
     // add words from array into hashset   
     HashSet<String> words = new HashSet<String>();  
     for(String word : wordArray) {  
       words.add(word);  
     }  
     return words;  
   }  
 }  

c)Responder
 public class Responder  
 {  
   /**  
     * Create a responder.  
    */  
   public Responder()  
   {  
   }  
   /**  
   * Generate a response.  
   * @return A string that should be displayed as the  
   * response  
   */  
   public String generateResponse()  
   {  
     return "That sounds interesting. Tell me more...";  
   }  
 }  

Berikut hasil screenshot bagan class dan outputnya




No comments:

Post a Comment