2012-04-01 6 views
0
ここ
ChatBot Class Modification: 

Modify the reply() method of the ChatBot class to recognize additional words and phrases. 

Part 1: Everyone must complete this section. 

When the userInput parameter value is:  The reply method should return: 
how do I quit       enter quit 
how do I exit       enter quit 
how do I stop       enter quit 
how do I ____       do you really want to do that 
how are you        I'm fine 
how ______        I don't know 

Add two additional words or phrases to recognize and respond to. 

ChatBot Client Modification: 

Modify the ChatBot client application to loop until the end-user enters "quit". 

はここ/チャットボットクライアントとクラス変更

** 
* Java Chatbot Service class 
* @author Blake 
* 3/5/2012 
*/ 

/** 
    * Default constructor. 
    */ 
public class Chatbot 
{ 
    private String name; /** Users name */ 
    private String introbot; /** Name of the Chatbot */ 
    private String reply; /** Replies to the input of the string name and string introbot */ 

    /** 
     * Constructs mutebot object 
     * @param mutebow - returns name of mutebot 
     */ 
    public Chatbot() 
     { 
      name = "MuteBot"; 
     } 


    /** 
    * Changes Name 
    * @param name - new name 
    */ 
    public void setName (String n) 
    { 
    name = n; 
    } 

    /** 
    * Accesses name 
    * @return a brand new name 
    */ 
    public String getName() 
    { 
    return name; 
    } 

    /** 
     * Accesses introbot 
     * @return name of mutebot 
     */ 
    public String introbot() 
    { 
    String intro = "Hello! My name is " + name; 
    return intro; 

    } 

    /** 
     * Accesses replay(String newuserinput) 
     * @return introbot reply to user input 
     */ 
    public String getreply(String newuserinput) 
    { 
     String reply = "I'm just learning to talk"; 

     if (newuserinput.equalsIgnoreCase("What")) 
      reply = "Why do you ask?"; 
     else 
      if (newuserinput.equalsIgnoreCase("Why")) 
      reply = "Why Not"; 
     else 
      if (newuserinput.equalsIgnoreCase("How")) 
      reply = "I don't know!"; 
     else 
      if (newuserinput.equalsIgnoreCase("Where")) 
      reply = "Anne Arundel Community College"; 
     else 
      if (newuserinput.equalsIgnoreCase("When")) 
      reply = "Tomorrow"; 
     else 
      if (newuserinput.equalsIgnoreCase("how do I quit")) 
      reply = "enter quit"; 
     else 
      if (newuserinput.equalsIgnoreCase("how do I exit")) 
      reply = "enter quit"; 
     else 
      if (newuserinput.equalsIgnoreCase("how do I stop")) 
      reply = "enter quit"; 
     else 
      if (newuserinput.equalsIgnoreCase("how are you")) 
      reply = "I'm fine"; 
     else 
      if (newuserinput.equalsIgnoreCase("how do you do")) 
      reply = "I am doing well"; 
     else 
      if (newuserinput.equalsIgnoreCase("how do I get out")) 
      reply = "By going through the door"; 
     else 
      if (newuserinput.indexOf("how do I") ==0) 
      { String substring = newuserinput.substring(8); 

      reply = "do you really want to do that" + substring; 
      } 
     else 
      if (newuserinput.indexOf("how") ==0) 
      { String substring = newuserinput.substring(10); 


      reply = "I don't know" + substring ; 
      } 



     return reply; 

    } 
} 

がある私のサービスクラスの私のクライアント/アプリケーションクラスです

/** 
* Java Chatbot Client class 
* @author Blake 
* 3/5/2012 
*/ 

import java.util.Scanner; 
public class ChatbotClient 
{ 
    public static void main(String[] args) 
    { 
     Scanner input = new Scanner(System.in); 

     Chatbot t = new Chatbot(); 
     System.out.print("What is your name? "); 
     String name = input.nextLine(); 

     System.out.println(t.introbot()); 

     System.out.print(name + "> "); 
     String reply = input.nextLine(); 

     System.out.println(t.getName() + "> " + t.getreply(reply)); 
     //while (reply < quit) 
     /*{ 
      quit++ 
      i = i + 1 

     }*/ 






    } 
} 

私はと間違ってやっているのか分かりませんこの部分はここをクリック

エンドユーザーが入るまで、ChatBotクライアントアプリケーションをループするように修正する "終了する"。

私はwhileループを作成しようとしていますが、これはユーザーが終了するまで続きます。

+0

いくつかのソースコードを貼り付けることで、あなたの疑問を起動しないでください。最初に質問してください。また、あなたは何が間違っているのか説明しませんでした。あなたの質問はどこですか? – Vincent

答えて

0

私は、次のコードは、あなたの要件のために働くべきだと思う:

import java.util.Scanner; 
public class ChatbotClient 
{ 
    public static void main(String[] args) 
    { 
     Scanner input = new Scanner(System.in); 

     Chatbot t = new Chatbot(); 
     System.out.print("What is your name? "); 
     String name = input.nextLine(); 

     System.out.println(t.introbot()); 

     System.out.print(name + "> "); 
     String reply = input.nextLine(); 

     while (!reply.equalsIgnoreCase("quit")){ 
     System.out.println(t.getName() + "> " + t.getreply(reply)); 
     System.out.print(name + "> "); 
     reply = input.nextLine(); 
     } 
    } 
}