Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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:

image text in transcribed

image text in transcribed

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_step_2

Step: 3

blur-text-image_step3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

OUTLINE the five steps in the labour relations process.

Answered: 1 week ago

Question

Examine various types of executive compensation plans.

Answered: 1 week ago

Question

1. What is the meaning and definition of banks ?

Answered: 1 week ago

Question

2. What is the meaning and definition of Banking?

Answered: 1 week ago

Question

3.What are the Importance / Role of Bank in Business?

Answered: 1 week ago