Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hi i have seen similar answers to this question before but the code when tested is incorrect so if you have a different answer please

Hi i have seen similar answers to this question before but the code when tested is incorrect so if you have a different answer please respond. thank you

using java

addWord: The parameter represents a case-sensitive word that has been found in a document. Because an instance must keep track of how many times each word has been added, the count of occurrences for that word must be increased by 1. You may assume that all strings passed to this method will consist only of one or more alphabetic characters and there is no need to check that this is the case. In other words, all parameters will be valid words. howMany: The parameter represents a case-sensitive word that has been found in a document. The number of times that the exact word has been passed to the addWord method must be returned. suffixCount: This method takes a single parameter and it must return the number of distinct words added so far to the processor that the parameter is a suffix of. It counts as a suffix if a word in the processor ends with the parameter but does not also exactly match the parameter. For instance: parameter "thing" matches all of: "something", "nothing" and "thing" but only the first two qualify as suffix matches. The count must represent distinct words, so each added word that contains the suffix must only be counted once. For instance, if "something" has been added 3 times, that only counts as 1 match for something. anagramCount: This method takes a single parameter and it must return the number distinct case-insensitive anagrams of the given word have been added to the processor. An anagram consists of exactly the same number of letters as the given word with each character occurring the same number of times. However, identical words are not considered to be anagrams. For instance: "and" is an anagram of "dan" but "nan" is neither an anagram of "naan" nor of nan. Note that because the match must be case-insensitive, Dan is also an anagram of and. However, because the match is case-insensitive, all of Dan, dan and DAN only count as a single match for any of and, AND and And. and And. Also each anagram is only counted once, regardless of how many times it has been added to the processor via addWord.

Dan saw it was time to take the risk and visit his Nan. The thing is, there was nothing to be lost, because something was bound to happen. If a call to addWord has been made for each word, in order, then the following would be the results of a sample of method calls: A call to howMany(to) would return 3 because it has been added 3 times . A call to countSuffixes(thing) would return 2 because it matches nothing and something but doesnt match thing. A call to countAnagrams(saw) would return 1 because only was is an anagram. The count is 1 even though was has been added 3 times.

public class TextProcessor { /** * Constructor for objects of class TextProcessor */ public TextProcessor() { } /** * Add a word to the processor. public void addWord(String word) { } /** * Get the number of times the given word has added * via addWord. * */ public int howMany(String word) { return 0; } /** * Return the number of distinct words str is a * suffix of in the words added so far. * * It counts as a suffix if a word ends with * str but str does not also match the whole word. * For instance: "thing" matches the following 3 examples: * "something" "nothing" "thing" * but only the first two qualify as proper suffix matches. * * Each word that contains the suffix must only be counted once, * so if "something" has been added 3 times, that only counts * as 1 match. */ public int suffixCount(String str) { return 0; } /** * Count the number of distinct case-insensitive anagrams * of the given word that have been added to the processor. * * An anagram consists of exactly the same number of * letters as the given word, each character occurring * the same number of times. It does not count as an * anagram if the two words are already identical. * * For instance: "and" is an anagram of "Dan" but * "nan" is neither an anagram of "naan" nor "nan". */ public int anagramCount(String word) { return 0; } }

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: 3

blur-text-image

Ace Your Homework with AI

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

Get Started

Recommended Textbook for

Modern Database Management

Authors: Jeffrey A. Hoffer Fred R. McFadden

4th Edition

0805360476, 978-0805360479

More Books

Students also viewed these Databases questions

Question

What are the purposes of promotion ?

Answered: 1 week ago

Question

Define promotion.

Answered: 1 week ago