2013-12-09 22 views
1

我在第2類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(); 
    } 
    } 
} 

回答

2

getResponseChatBotBotTest

ChatBot c = new ChatBot(); 
+0

omg你是天賜之物。我是一個白癡。謝謝 – user3083893

0

的Class BotTest確實不具有.getResponse(字符串)函數定義。 ChatBot雖然。