This problem is asking for me to write a method in the SentenceCounter class tha
ID: 3737333 • 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.
ounting Blanks e first thing our SentenceCounter ass will do is to count the number of Test lank characters our String contains.public void testCoun tBlanks () assertEquals (3, sc1.countBlanks (O) assertEquals (7, sc2.countBlanks 0) ve're going to write a method that returns an integer containing the number of blanks in the String. Following TDD as usual, let's use the test to figure out exactly what we are going to build. L Write just enough code to make this test compile and watch the test go RED. To make this test pass, we need a counting loop that will 'walk through" the string. At each position, a running count (held in another local variable) will be incremented if the character in that position is a blank. That running count is the value this method will return. Write the code to get to GREEN and then REFACTOR.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; iRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.