Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

This problem is asking for me to write a method in the SentenceCounter class tha

ID: 3737344 • Letter: T

Question

This problem is asking for me to write a method in the SentenceCounter class that will pass the test in the images above.

Strings Contain Strings Let's write a method that uses so me of those String methods (and has yet anoth the test: er loop!). Here's Make this test compile Test public void testCountOccurrences () and watch it go RED. At this point, you should be able to look at this test, and the name of the method, to figure out what we expect countOccurrences() is to do. Essentially, you need a loop that looks at each position of the array to see if it starts a substring that matches the parameter we were given. The easiest way to get to GREEN is to write that loop and, inside the loop, use the substring () method to pull out the part of the string you assertEquals (1, sc1.countoccurrences ("ence")) assertEquals (2, sc1.countOccurrences ("en")) assertEquals (1, sc2.countOccurrences ("that")) assertEquals (0, sc2.countoccurrences ("This")); want to check and then use the equals () method to see if it matches the parameter value. As always, REFACTOR before you move on.

Explanation / Answer

public class SentenceCounter { private String sentence; public SentenceCounter(String sentence) { this.sentence = sentence; } public String getSentence() { return sentence; } public int countBlanks() { int count = 0; for(int i = 0; i
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote