Question: (a) Design the wordCount method that, when given a Strings, counts the number of words in the list. Store the results in a HashMap

(a) Design the wordCount method that, when given a Strings, counts the number of words in the list. Store the(a) Design the generic lookup method that, when given an Map M and a value k of type K, returns the

(a) Design the wordCount method that, when given a Strings, counts the number of words in the list. Store the results in a HashMap . Assume that s is not cleaned. That is, you should first remove all punctuation (periods, commas, exclamation points, question marks, semi-colons, dashes, hashes, ampersands, asterisks, and parentheses) from s, producing a new string s'. Then, split the string based on spaces (remember tokenize?), and produce a map of the words to their respective counts. Do not factor case into your total; i.e., "fACTOR" and "factor" count as the same word. The ordering of the returned map is not significant. String s = "Hello world, the world is healthy, is it not? I certainly agree that the world is #1 and healthy." wordCount (s)-> [{"hello", 1}, {"world", 3}, {"the", 2} {"is", 3}, {"healthy", 2}, {"it", 1}, {"i", 1}, {"certainly", 1} {"agree", 1} {"that", 1}, {"1", 1}, {"and", 1}, {"not", 1}] (a) Design the generic lookup method that, when given an Map M and a value k of type K, returns the corresponding value (of type V) associated with the key k. If the key does not exist, return null. You will need to use the .equals method. (b) Design the generic stringifyList method that, when given an ArrayList L, returns a String of comma-separated values where each value is an element of L, but converted into a string. You'll need to use the .toString method.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

It appears that youve presented two separate tasks 1 Creating a wordCount method that removes punctuation from a string and counts the occurrences of ... View full answer

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 Programming Questions!