(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...
-
What happens to the period of a wave when the frequency decreases?
-
Assuming the dispersion relation \(\omega=A k^{\mathcal{s}}\), where \(\omega\) is the angular frequency and \(k\) the wave number of a vibrational mode existing in a solid, show that the respective...
-
The Consumer Product Safety Commission (https://www.cpsc.gov/) lists products that have been recalled and provides consumers with a telephone number for contacting the manu- facturer. Choose a...
-
The Cone Head House sells ice cream cones in a variety of flavors. Data for a recent week appear here: Revenue (1,000 cones @ $1.50 each) ...$1,500 Cost of ingredients...
-
Consider the following cash flows (in $1,000's) of three mutually exclusive projects for DJT, Inc. Assume that DJT's required rate of return is 10%. Consider the following cash flows (in $1,000's) of...
-
The following is information taken from the June 30, 2023, balance sheet of Tippleton Company: Part 1 During July, Tippleton Company recorded total sales of $904,000, all on credit. There were...
-
8. What is meant by Generally Accepted Accounting Principles, and do these principles add to the integrity of financial accounting information. Mention all principles and conventions.
-
Benjamin Franklin is credited with the following quote, "In this world, nothing is said to be certain, except death and taxes." In the United States, the Constitution defines the structure of the...
-
The websites www . kbb . com and www . edmunds.com provide information about a . creditworthiness of individuals. b . cars for sale. c . homes for sale. d . realtor grades. e . the Executive Director...
-
According to theory and literature, how can the issue of lack of digital knowledge arise in an organisation with references
-
Calculate the total amount and total interest for a principal amount of $1,340 invested for 1 year at a rate of compound interest of 6%, compounded quarterly.
-
You invest $ 2 0 0 per month for 4 0 years. How much will you have at the end of 4 0 years if your interest rate is 1 0 % ? Round your answer to the nearest whole dollar and do not use comma...
-
The security level in the school, the type of rules and the consequences of going against the rules and the level of strictness of the teacher in the school are the main variables in the research...
-
A consultant is beginning work on three projects. The expected profits from these projects are $50,000, $72,000, and $40,000. The associated standard deviations are $10,000, $12,000, and $9,000....
-
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...
-
Consider the following game trees. (a) Find all equilibria for the game tree on the left. Which of these are subgameperfect? (b) In the game tree on the right, the payoffs \ (a, b, c, d\) are...
-
Consider the following game tree. (a) What is the number of strategies of player I and of player II? How many reduced strategies does each of the players have? (b) Give the reduced strategic form of...
-
Consider a game \(G\) in strategic form. Recall that the commitment game derived from \(G\) is defined by letting player I choose one of his strategies \(x\), which is then announced to player II,...
Study smarter with the SolutionInn App