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:

Need help on a Java question to count the words. I almost

finished this problem. But I cannot finish pass three tests. The following

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 text. The words in the ...*/ static List getWords (String text) { // TODO: please implement the method: // words = new ArrayList(); if (text == null || text.length() == 0) { return words; } +/\\t+"), text.split( regex: +|\\t+").length); String[] splitWords = Arrays.copyOf(text.split( regex: Collections.addAzz(words, splitWords); return words; // --end--> } /**

This method tries to determine if the given word 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/**

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 text. The words in the ...*/ static List getWords (String text) { // TODO: please implement the method: // words = new ArrayList(); if (text == null || text.length() == 0) { return words; } +/\\t+"), text.split( regex: +|\\t+").length); String[] splitWords = Arrays.copyOf(text.split( regex: Collections.addAzz(words, splitWords); return words; // --end--> } /**

This method tries to determine if the given word 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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!