Question: With this class: public class SentenceCounter { private String sentence; public SentenceCounter(String sentence) { this.sentence = sentence; } public String getSentence() { return sentence; }
With this class:
public class SentenceCounter
{
private String sentence;
public SentenceCounter(String sentence)
{
this.sentence = sentence;
}
public String getSentence()
{
return sentence;
}
Add onto this code that would make this JUnit test pass:
@Test
public void testCounterBlanks()
{
assertEquals(3, sc1.countBlanks());
assertEquals(7, sc2.countBlanks());
}

C your code Counting Blanks The first thing our SentenceCounter class will do is to count the number of Test blank characters our String contains. public void testCountBlanks () We'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. assertEquals (3, scl.countBlanks ()) assertequals (7, sc2.countBlanks ()); 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 co to get to GREEN and then REFACTOR. unt is the value this method will return. Write the code
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
