Challenge: Basic String Manipulation
Develop an application for string manipulation, including counting characters, converting them to lowercase, and determining character occurrences using TDD.
We'll cover the following
Task and requirements
You’re given a string containing a sentence. Your task is to create a Java program that performs the following operations:
Count the total number of characters in the sentence, excluding spaces.
Convert the sentence to all lowercase characters.
Determine and print the number of occurrences of a specific character in the sentence.
Here are the simplified requirements for this challenge:
Create a Java class named
StringManipulator
with the following methods:countCharacters
: Takes a string as input and returns the total number of characters in the sentence, excluding spacesconvertToLowerCase
: Takes a string as input and returns the sentence with all lowercase characterscountOccurrences
: Takes a string and a character as input and returns the number of times the character appears in the sentence
Implement test cases for each of the above methods to verify their correctness.
Ensure that the initial test cases fail before writing the implementation code in the
StringManipulator
class.Implement the
StringManipulator
class to make the test cases pass.
Note: Use assertions to compare the expected result with the actual result returned.
Try it yourself
Add or modify the code in the widget below to implement your solution.
Get hands-on with 1400+ tech skills courses.