Rewrite Listing 21.9 to read the text from a text file. The text file is passed as
Question:
Rewrite Listing 21.9 to read the text from a text file. The text file is passed as a command-line argument. Words are delimited by whitespace characters, punctuation marks (,;.:?), quotation marks ('"), and parentheses. Count words in case-insensitive fashion (e.g., consider Good and good to be the same word). The words must start with a letter. Display the output in alphabetical order of words, with each word preceded by its occurrence count
Data from Listing 21.9
Transcribed Image Text:
1mport java. util.: 2 1 3 publ1c class CountOccurrence0fWords { publ1c stat1c void main(String[] args) { I/ Set text in a string String text = "Good morn1ng. Have a good class. " + "Have a good visit. Have fun!"; 4 6 7 8 II Create a TreeMap to hold words as key and count as value Map
1mport java. util.: 2 1 3 publ1c class CountOccurrence0fWords { publ1c stat1c void main(String[] args) { I/ Set text in a string String text = "Good morn1ng. Have a good class. " + "Have a good visit. Have fun!"; 4 6 7 8 II Create a TreeMap to hold words as key and count as value Map map = new TreeMapo (): 10 11 12 String[] words = text.split("[Is+1 \p{P}]"): for (1nt i = 0: i < words.length: i++) { String key = words [i].tolowerCase (): 13 14 15 1f (key. length () > 0) { 1f (Imap.containsKey (key)) { map. put (key. 1): 16 17 18 19 else { int value = map.get (key): 20 21 22 value++; 23 map. put (key, value): 24 25 26 27 28 II Display key and value for each entry
Fantastic news! We've Found the answer you've been seeking!
Step by Step Answer:
Answer rating: 75% (8 reviews)
import javautil import javaio public class Exercise2108 public static void mainString args if argsle...View the full answer
Answered By
Ehsan Mahmood
I’ve earned Masters Degree in Business Studies and specialized in Accounts & Finance. Couple with this, I have earned BS Sociology from renowned institute of Pakistan. Moreover, I have humongous teaching experience at Graduate and Post-graduate level to Business and humanities students along with more than 7 years of teaching experience to my foreign students Online. I’m also professional writer and write for numerous academic journals pertaining to educational institutes periodically.
4.90+
248+ Reviews
287+ Question Solved
Related Book For
Introduction To Java Programming And Data Structures Comprehensive Version
ISBN: 9780136520238
12th Edition
Authors: Y. Daniel Liang
Question Posted:
Students also viewed these Computer science questions
-
Rewrite each expression by eliminating parentheses and then combining like terms. a. 2 + 3(x - 4) b. (11 - 3x) - 2(4x + 5) c. 5.1 - 2.7(1 - (2x + 9.7))
-
In alphabetical order below are balance sheet items for Burnett Company at December 31, 2014. Prepare a balance sheet following the format of Illustration 1-7 Accounts payable ...... $65,000 Accounts...
-
Consider the Whooping Cough data file on the text CD. a. Identify the response variable and the explanatory variable. b. Construct a graph using bars to display the incidence rate of whooping cough...
-
8 D D D D P P P P P P P P P P P 10 Functions What is defusion. What is osnosis What is Tornicity The power house of the cell functions of the plasma? What is facilitated defusion? do they need ATP?...
-
Assume that X has a Normal distribution with a mean of -1.32 and a standard deviation of 0.34. Use the Normal table to find the following probabilities starting from X. Also sketch a standard Normal...
-
(a) Find 8! without a calculator. Show your work. (b) Use your calculator to nd 32!. (c) Which method would you use most often? Why?
-
What are the two categories of data mining and knowledge discovery software?
-
On December 1, 2015, Liang Chemical provides services to a customer for $90,000. In payment for the services, the customer signs a three-year, 10% note. The face amount is due at the end of the third...
-
Alice wants to buy apples, beets, and carrots. An apple, a beet, and a carrot cost 16 dollars, two apples and three beets cost 23 dollars, and one apple, two beets, and three carrots cost 35 dollars....
-
Sanlucas, Inc., provides home inspection services to its clients. The following is the company's trial balance dated June 1, current year. Sanlucas engaged in the following transactions in June. June...
-
Write a program that prompts the user to enter a text file name and displays the number of vowels and consonants in the file. Use a set to store the vowels A, E, I, O, and U.
-
Write a program that converts a Java file into an HTML file. In the HTML file, the keywords, comments, and literals are displayed in bold navy, green, and blue, respectively. Use the command line to...
-
A rectangular swimming pool is three times as long as it is wide. If the perimeter of the pool is 320 feet, what are its dimensions?
-
Final interest rate George Muoz, owner of Muoz Meat Products (MMP), is interested in a new project that will produce specialty microwave meat products. The project is estimated to last 5 years before...
-
Would you consider Adobe a high-performance organization? Why or why not? How do the practices in this case relate to the principles of empowerment, knowledge sharing, and employee engagement?
-
The theorists associated with EET have not formally defined communication. Where do you think "communication" occurs in this theory ? Provide evidence from the theory that might indicate how the...
-
Problem 7: Suppose a motor connected to a 130 V source draws 19 A when it first starts. Randomized Variables V=130 V 1 = 19 A Part (a) What is its resistance in Q? Numeric A numeric value is expected...
-
On January 1, 2018, Minimal, Inc., paid $80,000 for a 15% interest in Harrington Corporations common stock. This investee had assets with a book value of $225,000 and liabilities of $55,000. A...
-
A body is suspended vertically from an ideal spring of spring constant 2.5 N/m. The spring is initially in its relaxed position. The body is then released and oscillates about its equilibrium...
-
If you want to solve a minimization problem by applying the geometric method to the dual problem, how many variables and problem constraints must be in the original problem?
-
Rewrite Programming Exercise 18.9 using a helper method to pass the substring high index to the method. The helper method header is: public static void reverseDisplay(String value, int high) Write a...
-
Write a recursive method that displays a string reversely on the console using the following header: public static void reverseDisplay(String value) For example, reverseDisplay("abcd") displays dcba....
-
Modify Listing 18.2, ComputeFibonacci.java, so that the program finds the number of times the fib method is called. Listing 1 import java.util.Scanner; 2 3 public class ComputeFibonacci { 4 /** Main...
-
13. (5 points) What are the first four terms of each sequence: (a) an 4 2n Vn 0 (b) bn 6-3-2" Vn 0 (c) c = 4,cn 3 Cn-1-2 Vn 2 (d) d =-1, d=5-dn-1+n Vn 2 (e) eo 1, e1=1, ennen-1+nen-2+1 Vn2
-
23. A D flip-flop is connected as shown in Figure 6-85. Determine the Q output in relation to the clock. What specific function does this device perform? CLK D FIGURE 6-85 24. For the circuit in...
-
What is a survey? What is the purpose of a survey? Give examples of types of surveys or particular surveys used in psychological research. Describe the main steps in developing and administering a...
Study smarter with the SolutionInn App