1

我在第二堂课上遇到错误c.getResponse The method getResponse(String) is undefined for the type BotTest 如果有人想看看作业是什么,请看 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;

}

}

第二类测试代码 import 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();
    }
  }
}
4

2 回答 2

2

getResponse被定义为ChatBotBotTest

ChatBot c = new ChatBot();
于 2013-12-09T17:57:01.970 回答
0

Class BotTest 确实没有 .getResponse(String) 函数。ChatBot 可以。

于 2013-12-09T17:57:20.757 回答