Getting code error for a simple ChatBot program

312 Views Asked by At

I'm getting an error at the 2nd class c.getResponse The method getResponse(String) is undefined for the type BotTest If anyone wants to see what the assignment was heres the 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;

}

}

Second Class to test the code 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

There are 2 best solutions below

0
On BEST ANSWER

getResponse is defined for ChatBot not BotTest

ChatBot c = new ChatBot();
0
On

The Class BotTest indeed does NOT have the .getResponse(String) function. ChatBot does though.