Eliza

Tugas Pemrograman Berbasis Objek
Eliza

Kali ini saya akan membahas tentang aplikasi Eliza, dimana kita dapat bercakap-cakap dan mendapat jawaban dari perbincangan kita. Saya membutuhkan 3 class yaitu, SupportSystem, Responder, dan InputReader.

1. Source Code SupportSystem

 /**  
  * This class implements a technical support system. It is   
  * the top-level class in this project. The support sytem  
  * 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 project of class Responder to   
  * generate responses.  
  * It contains a loop that repeatedly reads input and   
  * generates output until the user wants to leave  
  *  
  * @author   Yuki Yanuar Ratna  
  * @version   0.1(08/10/2018)  
  */  
 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)  
     {  
       String input = reader.getInput();  
       if(input.startsWith("bye"))  
       {  
         finished=true;  
       }  
       else  
       {  
         String response = responder.generateResponse();  
         System.out.println(response);  
       }  
     }  
     printGoodbye();  
   }  
   /**  
    * Print a welcome message to the screen.  
    */  
   private void printWelcome()  
   {  
     System.out.println("Welcome to the DodgySoft Technical Support System.");  
     System.out.println();  
     System.out.println("Please tell us about your prroblem.");  
     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 goo-bye message to the screen  
    */  
   private void printGoodbye()  
   {  
     System.out.println("Nice talking to you. Bye...");  
   }  
 }  

2. Source Code Responder

 /**  
  * The Responder class represents a response generator object.  
  * It is used to generate an automatic response to an input string.  
  *  
  * @author   Yuki Yanuar Ratna  
  * @version   0.1(08/10/2018)  
  */  
 public class Responder  
 {  
   /**  
    * Construct a Responder-nothing to do  
    */  
   public Responder ()  
   {  
   }  
   /**  
    * Generarte a response  
    * @return A string that should be displayed as the response  
    */  
   public String generateResponse()  
   {  
     return "That sounds interesting. Tell me more...";  
   }  
 }  

3. Source Code InputReader

 import java.util.Scanner;  
 /**  
  * This is a inputReader class  
  *  
  * @author   Yuki Yanuar Ratna  
  * @version   0.1(08/10/2018)  
  */  
 public class InputReader  
 {  
   private Scanner reader;  
   public InputReader()  
   {  
     reader = new Scanner(System.in);  
   }  
   public String getInput()  
   {  
     System.out.println("> "); //print prompt  
     String inputLine = reader.nextLine();  
     return inputLine;  
   }  
 }  

4. Tampilan Akhir




Sekian, semoga bermanfaat.

Komentar

Postingan populer dari blog ini

Tugas Membuat Jam Digital

Codeigniter "Toko Buah"

Personal Web