Question
Need help on a Java question to count the words. I almost finished this problem. But I cannot finish pass three tests. The following is
Need help on a Java question to count the words.
I almost finished this problem. But I cannot finish pass three tests.
The following is the method I implemented:
getWords method: split words from given text, the words are separated by ' ' and '\t'.
isMatch method: determine if the word satisfies rules in the problem, like not null, at least three characters and etc. Details can see in my code.
countWord method: count how many words extracted in getWords which also satisfy the rules define by isMatch.
Following is my code:
There are three tests I cannot pass, which I don't know how to deal with it.
@Test void should_trim_start_and_end_whitespace_characters() { assertIterableEquals(Collections.singletonList("word"), WordsCounter.getWords(" word\t\t")); assertIterableEquals(Collections.singletonList("word\f"), WordsCounter.getWords(" word\f\t")); assertIterableEquals(Arrays.asList("word", "count"), WordsCounter.getWords(" word\t\tcount ")); }
@Test void should_not_match_for_special_letter_character() { assertFalse(WordsCounter.isMatch((char)255 + "ord2")); } @Test void should_not_match_other_digits_character() { assertFalse(WordsCounter.isMatch("word\u0660")); }
I think you should preserve much of my code cause there're many other tests I already passed but I did not put them here.
Thank you very much.
1/**Please implement the {@link WordsCounter#countWord(String)} method with the help of ...* public class WordsCounter { 3 private Words Counter() { } /** This method will try to split words from given This method tries to determine if the given Please implement the {@link WordsCounter#countWord(String)} method with the help of ...* public class WordsCounter { 3 private Words Counter() { } /** This method will try to split words from given This method tries to determine if the given text
. The words in the ...*/ static Listword
satisfies the following ...*/ static boolean isMatch(String word) { // TODO: please implement the method: // } public static int countWord(String text) { // TODO: please implement the method: // } 1/** text
. The words in the ...*/ static Listword
satisfies the following ...*/ static boolean isMatch(String word) { // TODO: please implement the method: // } public static int countWord(String text) { // TODO: please implement the method: // }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started