gpt4 book ai didi

java - 获取简单 ChatBot 程序的代码错误

转载 作者:行者123 更新时间:2023-11-30 04:07:12 25 4
gpt4 key购买 nike

我在第二节课时遇到错误 c.getResponseBotTest 类型的 getResponse(String) 方法未定义如果有人想看看作业是什么,这里有 pdf: http://www.cs.stonybrook.edu/~tashbook/fall2013/cse110/project-1.pdf

  import java.util.*;

public class ChatBot {
public String getResponse(String input) {
int i = 0;
int found = input.indexOf("you", i);
if (found == -1)

return "I'm not important. Let's talk about you instead.";


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

if (x == 4) {
return "Tell me more about" + " " + longestWord(input);
}
if (x == 5) {
return "Why do you think" + " " + longestWord(input) + " "
+ "is important?";
} else if (x > 5) {
return "Now we are getting somewhere. How does" + " "
+ longestWord(input) + " " + "affect you the most";
}
else
return "I don't understand";
}


private String longestWord(String input) {
String word, longestWord = "";
Scanner turtles = new Scanner(input);
while (turtles.hasNext()) {
word = turtles.next();
if (word.length() > longestWord.length())
longestWord = word;
}
return longestWord;

}

}

第二节测试代码 导入java.util.*;

public class BotTest {
public static void main(String[] args) {
Scanner newturtles = new Scanner(System.in);
System.out.println("What would you like to talk about?");
String input = newturtles.nextLine();
BotTest c = new BotTest();
while (!input.toUpperCase().equals("GOODBYE")) {
System.out.println(c.getResponse(input));
input = newturtles.nextLine();
}
}
}

最佳答案

getResponse 是为 ChatBot 定义的,而不是为 BotTest

ChatBot c = new ChatBot();

关于java - 获取简单 ChatBot 程序的代码错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20477314/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com