Write Java class for counting word occurrences.

1)With that class it should be possible to add word and each time only one word can be added. It should be possible to add different words and each word can be repeated.

2)Allowed characters for word are uppercase and lowercase characters from English alphabet.

3)The class should allow counting of how many times given word were added to class. If the word was not added before then counting of such word should return zero occurrences.

4)The class should also allow counting of words in 'case sensitive' and 'case insensitive' mode. Uppercase and lowercase characters in words should be treated as distinct 'case sensitive' or equivalent 'case insensitive'.

5)It should be also possible to add sentence where can be added multiple words separated by ";" character.

6)Write unit tests in JUnit or TestNG and cover all the functionalities of the written class.

Examples:

  • When "cat" then "dog" and again "cat" is added then the class can count that "cat" was added 2 times. It can also count that "dog" was added 1 time.
  • With added words "cat", "Cat" ,"CAT" When it is called count for occurrences of "Cat" word the class should return 1 occurrence in 'case sensitive' mode and in 'case insensitive' it should return 3 occurrences of the input word.
Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.