(a) Design the wordCount method that, when given a Strings, counts the number of words in...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
(a) Design the wordCount method that, when given a Strings, counts the number of words in the list. Store the results in a HashMap<String, Integer>. 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<K, V> 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<T> 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. (a) Design the wordCount method that, when given a Strings, counts the number of words in the list. Store the results in a HashMap<String, Integer>. 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<K, V> 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<T> 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.
Expert Answer:
Answer rating: 100% (QA)
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 the full answer
Related Book For
Management Accounting
ISBN: 9780730369387
4th Edition
Authors: Leslie G. Eldenburg, Albie Brooks, Judy Oliver, Gillian Vesty, Rodney Dormer, Vijaya Murthy, Nick Pawsey
Posted Date:
Students also viewed these programming questions
-
(a) Design the wordCount method that, when given a String s, 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...
-
A company has prepared the following summary from its functional budgets for the year ended 30th September 2013. $000 $000 Sales (100,000 units) 1,500Opening inventory (zero units)nilProduction costs...
-
Write a program to count the number of times the words in an input text file occur. The WordCount Structure Define a C++ struct called WordCount that contains the following data members: An array of...
-
Suppose you buy Bond A at time=0. It is a 2-year, risk-free bond with coupon rate of 7% that compounds annually, and it has a face value of $1,000. (3 points) a) At time = 0, suppose you buy Bond A...
-
Determine the moment of inertia for the shaded area about the y axis. Use Simpson's rule to evaluate the integral. Given: a = 1 m b = 1 m
-
A catering manager used a flexible budget to analyze July's operating results. The utilities expense for the July was $925 and the flexible budget's utilities expense was $1,100. Would this outcome...
-
Assume that cash flow is given by \(y=S_{T} W+\left(F_{T}-F_{0} ight) h\). Let \(\sigma_{S}^{2}=\operatorname{var}\left(S_{T} ight), \sigma_{F}^{2}=\operatorname{var}\left(F_{T} ight)\), and...
-
Your firm is contemplating the purchase of a new $410,000 computer-based order entry system. The system will be depreciated straight-line to zero over its five-year life. It will be worth $30,000 at...
-
(Corporate income tax) The William B. Waugh Corporation is a regional Toyota dealer. The firm sells new and used trucks and is actively involved in the parts business. During the most recent year the...
-
Metro Land is a country located on a 2D Plane. They are having asummer festival for everyone in the country and would like tominimize the overall cost of travel for their citizens. Costs oftravel are...
-
Find the distinct roots: f(x) = -(x + 5) + 1. Do not include "x =" in your answer, and if there is more than one distinct root, list your answers separated by commas. For example, if you found x = 1...
-
Martin Corporation is planning to issue 3,000 shares of its own $10 par value ordinary shares for two acres of land to be used as a building site. Instructions (a) What general rule should be applied...
-
Rockland Corporation earned net income of R$300,000 in 2015 and had 100,000 ordinary shares outstanding throughout the year. Also outstanding all year was R$800,000 of 10% bonds, which are...
-
Yilmaz Company is provided a grant by the local government to purchase land for a building site. The grant is a zero-interest-bearing note for 5 years. The note is issued on January 2, 2015, for 5...
-
Mask Company has 30,000 shares of 10 par value ordinary shares authorized and 20,000 shares issued and outstanding. On August 15, 2015, Mask purchased 1,000 shares of treasury shares for 18 per...
-
DiCenta Corporation reported net income of 270,000 in 2015 and had 50,000 ordinary shares outstanding throughout the year. Also outstanding all year were 5,000 shares of cumulative preference shares,...
-
Grains are a significant source of carbohydrates. In nature, grains are composed of three main parts. When all three parts of the grain are present in their original proportion, it is considered a...
-
As long as we can't lose any money, we have a risk-free investment." Discuss this comment. Q2: Both investing and gambling can be defined as "undertaking risk in order to earn a profit." Explain how...
-
You are about to start a coffee shop business. What do you understand by cost behavior? Explain how your accountants could help you in building an understanding of cost behavior. Identify the likely...
-
Mirror Industries laminating division, BrightShine, incurred the following costs and expenses in the last period. During the period, BrightShine produced 300 000 units of laminated board, which were...
-
SmallScale Publishing has now been operating for a couple of years. Sales have been growing and management have been excited about business performance. Currently the business sells two very popular...
-
In the research on leader behaviors, which style of leadership describes the preferred high-high combination? (a) transformational (b) transactional (c) laissez-faire (d) democratic
-
When managers use offers of rewards and threats of punishments to try to get others to do what they want them to do, they are using which type of power? (a) formal authority (b) position (c) referent...
-
In terms of leadership behaviors, someone who focuses on doing a very good job of planning work tasks, setting performance standards, and monitoring results would be described as _________. (a) task...
Study smarter with the SolutionInn App