-4

Javaでチャットボットを作りたいのですが、始め方がわかりません。次のコードを試しましたが、正確に必要なものが得られません。このプログラムでは、あらゆる可能性のある質問を書かなければなりませんでした。誰かが解決策を持っている場合は、私を助けてください。

import java.io.*;

public class Chatbot 
{
public static void main(String[]args) throws IOException
{
    String hel = new String("Hello");
    String hel1 = new String("HELLO");
    String hel2 = new String("hello");
    String hel3 = new String("Hii");
    String hel4 = new String("Hiii");
    String hel5 = new String("hii");
    String hel6 = new String("hiii");

    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        System.out.println("What is Your Name?");
        String name = br.readLine();
        System.out.println("Hello "+name+"..");
        String hellorep = br.readLine();
        if(hellorep .equals(hel))
        {
            System.out.println("Hello there...");
        }
        else if(hellorep .equals(hel1))
        {
            System.out.println("Hello there...");
        }
        else if(hellorep .equals(hel2))
        {
            System.out.println("Hello there...");
        }
        else if(hellorep .equals(hel3))
        {
            System.out.println("Hii");
        }
        else if(hellorep .equals(hel4))
        {
            System.out.println("Hiii");
        }
        else if(hellorep .equals(hel5))
        {
            System.out.println("Hii");
        }
        else if(hellorep .equals(hel6))
        {
            System.out.println("Hiii");
        }
        else
        {
            System.out.println("Please type Again I Didn't get you..");
        }
    }
}
4

1 に答える 1

0

これをウィンドウで作成したい場合は、jtextfield を使用して actionlistener を追加できます。コンソールでこれを作成したい場合は、input を使用します。

次に、メッセージを取得し、変数に保存してから、応答メソッドでこれを行います

if(STRINGVARIABLENAME.contains("Your word that you want it to check if it contains")) { then make the bot respond by Console or just do JTEXTFIELDNAME.setText("ANSWER HERE") }

このようにifの後にelse ifを実行して、できるだけ多くの応答の可能性を追加します

if(){ } else if(STRINGVARIABLENAME.contains("")){ }

これは何度でも行うことができ、そこにチャットボットがあります:D

于 2016-02-05T17:57:00.197 に答える