Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/327.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
类TestChatBot的方法未定义? import java.util.*; 公共类TestChatBot { 公共静态void main(字符串[]args) { 扫描仪输入=新扫描仪(System.in); 字符串x=input.nextLine(); TestChatBot e=新的TestChatBot(); { String prompt=“您想谈什么?”; System.out.println(提示); 字符串userInput=input.nextLine(); 而(!userInput.equals(“再见”)) { System.out.println(e.getResponse()); userInput=input.nextLine(); } } } 公共类聊天机器人 { 公共字符串getResponse(字符串输入) { 扫描仪用户输入=新扫描仪(输入); input=userInput.nextLine(); 最长单词(输入); String关键字=“你”; int you=input.indexOf(关键字); 如果(您>=0) return“我不重要,让我们谈谈你们。”; if(input.length()最长的.length()) 最长=温度; } 返回时间最长; } } }_Java_Class_Methods_Chatbot - Fatal编程技术网

类TestChatBot的方法未定义? import java.util.*; 公共类TestChatBot { 公共静态void main(字符串[]args) { 扫描仪输入=新扫描仪(System.in); 字符串x=input.nextLine(); TestChatBot e=新的TestChatBot(); { String prompt=“您想谈什么?”; System.out.println(提示); 字符串userInput=input.nextLine(); 而(!userInput.equals(“再见”)) { System.out.println(e.getResponse()); userInput=input.nextLine(); } } } 公共类聊天机器人 { 公共字符串getResponse(字符串输入) { 扫描仪用户输入=新扫描仪(输入); input=userInput.nextLine(); 最长单词(输入); String关键字=“你”; int you=input.indexOf(关键字); 如果(您>=0) return“我不重要,让我们谈谈你们。”; if(input.length()最长的.length()) 最长=温度; } 返回时间最长; } } }

类TestChatBot的方法未定义? import java.util.*; 公共类TestChatBot { 公共静态void main(字符串[]args) { 扫描仪输入=新扫描仪(System.in); 字符串x=input.nextLine(); TestChatBot e=新的TestChatBot(); { String prompt=“您想谈什么?”; System.out.println(提示); 字符串userInput=input.nextLine(); 而(!userInput.equals(“再见”)) { System.out.println(e.getResponse()); userInput=input.nextLine(); } } } 公共类聊天机器人 { 公共字符串getResponse(字符串输入) { 扫描仪用户输入=新扫描仪(输入); input=userInput.nextLine(); 最长单词(输入); String关键字=“你”; int you=input.indexOf(关键字); 如果(您>=0) return“我不重要,让我们谈谈你们。”; if(input.length()最长的.length()) 最长=温度; } 返回时间最长; } } },java,class,methods,chatbot,Java,Class,Methods,Chatbot,在我的ChatBotTest类中,它表示我的getResponse()方法对于类TestChatBot是未定义的。。。我真的不明白为什么它会这样说,它会阻止我的代码运行。我对Java非常陌生,所以我为糟糕/草率的编码感到抱歉。非常感谢您的帮助,谢谢 import java.util.*; public class TestChatBot { public static void main(String [] args) { Scanner inpu

在我的ChatBotTest类中,它表示我的getResponse()方法对于类TestChatBot是未定义的。。。我真的不明白为什么它会这样说,它会阻止我的代码运行。我对Java非常陌生,所以我为糟糕/草率的编码感到抱歉。非常感谢您的帮助,谢谢

      import java.util.*;

public class TestChatBot 
{
    public static void main(String [] args)
    {
        Scanner input = new Scanner(System.in);
        String x = input.nextLine();


        TestChatBot e = new TestChatBot();
        {
            String prompt = "What would you like to talk about?";
            System.out.println(prompt);

            String userInput = input.nextLine();

            while(!userInput.equals("Goodbye"))
            {
                System.out.println(e.getResponse());
                userInput = input.nextLine();
            }
        }

    }

public class ChatBot 
{

    public String getResponse(String input)
    {
        Scanner userInput = new Scanner(input);
        input = userInput.nextLine();

        longestWord(input);

        String keyword = "you";
        int you = input.indexOf(keyword);

        if (you >= 0)
            return "I'm not important. Let's talk about you.";

        if (input.length() <= 3)
            return "Maybe we should move on. Is there anything else you would like to 
                        talk about?";

        if (input.length() == 4)
            return "Tell me more about " + input;

        if(input.length() == 5)
            return "Why do you think " + input + "is important?";

        else 
            return "Now we're getting somewhere. How does " + input + "affect you the 
                most?";
    }

    private String longestWord(String x)
    {
        Scanner input = new Scanner(x);     

        String longest = "";

        String temp = input.next();

        while (input.hasNext())
        {
            if (temp.length() > longest.length())
                longest = temp;
        }   

        return longest;

        }




         }
    }
应该是

TestChatBot e = new TestChatBot();
TestChatBox
没有
getResponse()

另外,您的
getResponse
接受一个字符串参数。我想您想将
userInput
传递给它

ChatBot e = new ChatBot();
应该是

TestChatBot e = new TestChatBot();
TestChatBox
没有
getResponse()

另外,您的
getResponse
接受一个字符串参数。我想您应该将
userInput
传递给它

ChatBot e = new ChatBot();

您是否在
TestChatBot
类或
ChatBot
类中声明了
getResponse
?您是否在
TestChatBot
类或
ChatBot
类中声明了
getResponse
类中声明了
getResponse
?此外,OP需要将
userInput
传递到
getResponse()
-它有一个
字符串
参数,但是没有传递任何参数。此外,OP需要将
userInput
传递到
getResponse()
-它有一个
字符串
参数,但没有传递任何参数。