Ask your own question, for FREE!
Computer Science 13 Online
OpenStudy (ellecullen):

Magpie Homework help please: I need help with Tracing method calls: findKeyword("She's my sister", "sister", 0); findKeyword("Brother Tom is helpful", "brother", 0); findKeyword("I can't catch wild cats.", "cat", 0); findKeyword("I know nothing about snow plows.", "no", 0);

OpenStudy (ellecullen):

method I was given: private int findKeyword(String statement, String goal, int startPos) { String phrase = statement.trim(); int psn = phrase.toLowerCase().indexOf(goal.toLowerCase(), startPos); while (psn >= 0) { String before = " ", after = " "; if (psn > 0) { before = phrase.substring (psn - 1, psn).toLowerCase(); } if (psn + goal.length() < phrase.length()) { after = phrase.substring(psn + goal.length(), psn + goal.length() + 1).toLowerCase(); } /* determine the values of psn, before, and after at this point in the method. */ if (((before.compareTo ("a") < 0 ) || (before.compareTo("z") > 0)) && ((after.compareTo ("a") < 0 ) || (after.compareTo("z") > 0))) { return psn; } psn = phrase.indexOf(goal.toLowerCase(), psn + 1); } return -1; }

OpenStudy (ellecullen):

I also havethis:

OpenStudy (ellecullen):

@wio

OpenStudy (ellecullen):

@wio

OpenStudy (anonymous):

I don't know what you're trying to do.

OpenStudy (ellecullen):

For homework, I have to trace 4 method calls: findKeyword("She's my sister" , "sister" ,0); findKeyword("Brother Tom is helpful" , "brother" ,0); findKeyword("I can't catch wild cats" , "cat" ,0); findKeyword("I know nothing about snow plows" , "no" ,0); If you look at the file I attached, there is a table that I should complete for each method call.

OpenStudy (ellecullen):

I started completing the table for the first one, but I'm having trouble with it. I attached what I did so far:

OpenStudy (anonymous):

You have to look at each line of the program and figure out what it will do.

OpenStudy (anonymous):

Each statement does something simple.

OpenStudy (ellecullen):

Can you check if I did the one for number 2 right? I'll attach it.

OpenStudy (ellecullen):

Iran the phrase number 3 times and it showed me something different each time. I was also watching this: https://www.youtube.com/watch?v=lxgJzeWne-o&feature=youtu.be

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!