A+ Computer Science Magpie Chatbot Activity 4 Worksheet KEY
A+ Computer Science Magpie Chatbot Activity 4 Worksheet KEY
else
{
int pos = findKeyword(statement, "you", 0);
The three parameter findKeyword method is used. The method is called the first time with a
starting position of 0 to search the string from the beginning to find the keyword "you". If "you" is
found, then the findKeyword method calls the transformYouMeStatement method. The
transformYouMeStatement method calls the three parameter findKeyword method twice to find
the position of you (starting position of 0) and then me (starting position of where you is found + 3).
Calling the three paramenter version of findKeyword ensures that me is found after you.
e. I want some ice cream. Would you really be happy if you had some ice cream?
f. I would like you to do your homework. Why do you would like me?
2. In your lab, you altered the code to have the chatbot respond to "I want something" statements.
Would the order in which you test "I want something" statements and "I want to" statements affect the
way in which the chatbot responds to both types of statements? Explain your answer.
If "I want something" is tested before "I want to", the chatbot will never respond correctly to "I want to"
statements. All of the "I want to" statements will be answered with "Would you really be happy if you
had…", the "I want something" response.
3. Explain how this portion of the getResponse method ensures that the word you is found before the
word me in statement.
else
{
int pos = findKeyword(statement, "you", 0);
The transformYouMeStatement method calls the three parameter findKeyword method twice to
find the position of you (starting position of 0) and then me (starting position of where you is found +
3). Calling the three paramenter version of findKeyword ensures that me is found after you.