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);
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; }
I also havethis:
@wio
@wio
I don't know what you're trying to do.
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.
I started completing the table for the first one, but I'm having trouble with it. I attached what I did so far:
You have to look at each line of the program and figure out what it will do.
Each statement does something simple.
Can you check if I did the one for number 2 right? I'll attach it.
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
Join our real-time social learning platform and learn together with your friends!