You will create a class called and each instance will have: WordStatistics.java. You should be able...
Fantastic news! We've Found the answer you've been seeking!
Transcribed Image Text:
You will create a class called and each instance will have: WordStatistics.java. You should be able to create many instances of this class, its own text attribute, which will be of type String. This variable, text, will store a few sentences that will be parsed in other methods within Wordstatistics. • its own history attribute, which will be of type String. history stores the date in which this text was published in the format "Published_18700118" meaning year 1870, January 18. Across all instances of this class, we also want to store/record: . the total number of words ever counted by a WordStatistics instance via the method count InitWords (), which is described in more detail below. Name this variable totalWordCount and declare it with the correct modifier to ensure it will update for all instances of Wordstatistics. the length of the longest sentence ever recorded by a WordStatistics instance. Name this variable longestSentence Length. The length of a sentence will be defined by the number of words it contains. If the longest sentence ever found was "The little dog laughed to see such sport, and the dish ran away with the spoon." Then longest SentenceLength should be set to 16 for all instances of WordStatistics. Wordstatistics.java will have the following constructor: two-argument constructor, that takes in text as the first parameter and history as the second parameter. Both are of type String. WordStatistics.java will have the following methods: (For all methods within Wordstatistics.java, you may assume that sentences will always be separated by a period ('.'). That is, no other punctuation ending a sentence will appear, such as '?' or '!'. You can also assume that any character within a sentence that is not a letter is a comma (",).) countInitWords () takes in an integer as a parameter that indicates how many initial unique words to count and return a string [] [] where each subarray holds the word that was counted and its frequency. O O The int parameter stores the number of unique initial words in text that will have their frequencies counted throughout text. The case (upper or lower) of the text should not differentiate one word from another. For example, if text = "Hey diddle, diddle, the • . longestSentence () should return the length of the longest sentence within that specific instance's text and print the longest sentence. The length of a sentence will be defined by the numbers of words it contains. For example, if text = "Hey diddle, diddle, the cat and the fiddle. The cow jumped over the moon. The little dog laughed to see such sport, and the dish ran away with the spoon." Then longest Sentence () should return 16 and print: O the 7 cat 1 and 2 cat and the fiddle. The cow jumped over the moon. The little dog laughed to see such sport, and the dish ran away with the spoon." And the integer passed in was 5. Then countInitWords () should return the following array: [["hey", "1"], ["diddle", "2"], ["the", "7"], ["cat", "1"], ["and", "2"]] The initially recorded word should be stored in the returned array as its lowercase version. Make sure you are updating appropriate instance variables. The total words counted within this method in the example above is 1 + 2 +7 +1 +2 = 13. countInitWords () should not print anything. O "The little dog laughed to see such sport, and the dish ran away with the spoon." Make sure you are updating appropriate instance variables. textAge () calculate and return the age of the text (in years) by subtracting the year in which it was published from 2022 and adding 1. For example, if history="Published_18700101", then textAge () should return 153 because 2022-1870+ 1. textAge () should not print anything. Driver.java You will also create a Driver.java file to test your code. Within the main method, you will need to use the Scanner class to get user input to set the text of a WordStatistics instance. Use the constructor you've created in WordStatistics.java to initialize a WordStatistics instance with the user inputted text. The output of the main method in Driver.java should be the following (assuming text is the same as above): Set text: (user inputted text} Enter the initial number of words: 5 Word Counts: hey 1 diddle 2 * {} should be omitted from the actual output *5 is a user inputted number Longest Sentence: The little dog laughed to see such sport, and the dish ran away with the spoon. Age of text: 153 You will need to call the methods you created in a specific order to get the desired output, as well as some iterative logic to correctly print a String [] []. You should also make sure you are checking the values of your static variables and that they only change when you expect them too. You are free to add additional output lines to facilitate testing all of your methods and variables, as long as it includes the output shown above. Here are some methods that you may find useful throughout your code: O int Integer.parseInt(String s); O String String.value of (int i); o In the Scanner class: String next(); boolean hasNext () In the String Class: ■ String toLowerCase(); Even though you are free to implement your own program style, you should think carefully about the design of your program and its classes. To achieve the best score, you should follow the principles of modularity and encapsulation in your design. Try not to overload any one class or method with too much to do. You will create a class called and each instance will have: WordStatistics.java. You should be able to create many instances of this class, its own text attribute, which will be of type String. This variable, text, will store a few sentences that will be parsed in other methods within Wordstatistics. • its own history attribute, which will be of type String. history stores the date in which this text was published in the format "Published_18700118" meaning year 1870, January 18. Across all instances of this class, we also want to store/record: . the total number of words ever counted by a WordStatistics instance via the method count InitWords (), which is described in more detail below. Name this variable totalWordCount and declare it with the correct modifier to ensure it will update for all instances of Wordstatistics. the length of the longest sentence ever recorded by a WordStatistics instance. Name this variable longestSentence Length. The length of a sentence will be defined by the number of words it contains. If the longest sentence ever found was "The little dog laughed to see such sport, and the dish ran away with the spoon." Then longest SentenceLength should be set to 16 for all instances of WordStatistics. Wordstatistics.java will have the following constructor: two-argument constructor, that takes in text as the first parameter and history as the second parameter. Both are of type String. WordStatistics.java will have the following methods: (For all methods within Wordstatistics.java, you may assume that sentences will always be separated by a period ('.'). That is, no other punctuation ending a sentence will appear, such as '?' or '!'. You can also assume that any character within a sentence that is not a letter is a comma (",).) countInitWords () takes in an integer as a parameter that indicates how many initial unique words to count and return a string [] [] where each subarray holds the word that was counted and its frequency. O O The int parameter stores the number of unique initial words in text that will have their frequencies counted throughout text. The case (upper or lower) of the text should not differentiate one word from another. For example, if text = "Hey diddle, diddle, the • . longestSentence () should return the length of the longest sentence within that specific instance's text and print the longest sentence. The length of a sentence will be defined by the numbers of words it contains. For example, if text = "Hey diddle, diddle, the cat and the fiddle. The cow jumped over the moon. The little dog laughed to see such sport, and the dish ran away with the spoon." Then longest Sentence () should return 16 and print: O the 7 cat 1 and 2 cat and the fiddle. The cow jumped over the moon. The little dog laughed to see such sport, and the dish ran away with the spoon." And the integer passed in was 5. Then countInitWords () should return the following array: [["hey", "1"], ["diddle", "2"], ["the", "7"], ["cat", "1"], ["and", "2"]] The initially recorded word should be stored in the returned array as its lowercase version. Make sure you are updating appropriate instance variables. The total words counted within this method in the example above is 1 + 2 +7 +1 +2 = 13. countInitWords () should not print anything. O "The little dog laughed to see such sport, and the dish ran away with the spoon." Make sure you are updating appropriate instance variables. textAge () calculate and return the age of the text (in years) by subtracting the year in which it was published from 2022 and adding 1. For example, if history="Published_18700101", then textAge () should return 153 because 2022-1870+ 1. textAge () should not print anything. Driver.java You will also create a Driver.java file to test your code. Within the main method, you will need to use the Scanner class to get user input to set the text of a WordStatistics instance. Use the constructor you've created in WordStatistics.java to initialize a WordStatistics instance with the user inputted text. The output of the main method in Driver.java should be the following (assuming text is the same as above): Set text: (user inputted text} Enter the initial number of words: 5 Word Counts: hey 1 diddle 2 * {} should be omitted from the actual output *5 is a user inputted number Longest Sentence: The little dog laughed to see such sport, and the dish ran away with the spoon. Age of text: 153 You will need to call the methods you created in a specific order to get the desired output, as well as some iterative logic to correctly print a String [] []. You should also make sure you are checking the values of your static variables and that they only change when you expect them too. You are free to add additional output lines to facilitate testing all of your methods and variables, as long as it includes the output shown above. Here are some methods that you may find useful throughout your code: O int Integer.parseInt(String s); O String String.value of (int i); o In the Scanner class: String next(); boolean hasNext () In the String Class: ■ String toLowerCase(); Even though you are free to implement your own program style, you should think carefully about the design of your program and its classes. To achieve the best score, you should follow the principles of modularity and encapsulation in your design. Try not to overload any one class or method with too much to do.
Expert Answer:
Answer rating: 100% (QA)
Text Parsing using Java Procedure WordStatistics class is defined with suggested variables and metho... View the full answer
Related Book For
A Concise Introduction to Logic
ISBN: 978-1305958098
13th edition
Authors: Patrick J. Hurley, Lori Watson
Posted Date:
Students also viewed these programming questions
-
In this lab assignment, you will create a Java application that sorts a stack recursively. Consider the following algorithm to sort the entries in a stack S 1: 1. First create two empty stacks, S 2...
-
In this final assignment, you will create a new script that will simplify the administrative task of creating new secured users on a Linux box. Recall that in Ubuntu, a new user's home directory is...
-
Create a class called Heater, that contains four fields, temperature, increment, max and min, all of whose type is double. Make sure you write a description of your new Class in the comments, with...
-
A 0.1 cm thick flat copper plate, 2.5 m x 2.5 m square is to be cooled in a vertical position. The initial temperature of the plate is 90?C with the ambient fluid at 30?C. The fluid medium is either...
-
Tinh exchanges business equipment with an adjusted basis of $55,000 (initial basis was $105,000) for business equipment worth $42,000 and $20,000 in cash. a. What is Tinh's realized gain or loss on...
-
Butler Corp. maintains its financial records on the cash basis of accounting. Interested in securing a long-term loan from its regular bank, Butler Corp. requests you to convert its cash-basis income...
-
Journalize the following transactions for the Jazz Man music store. a. Purchased $8,700 of merchandise on account, terms 2/10, n/30, FOB ship ping point. b. Paid $175 to the freight company for the...
-
If a computer system does not have relocation hardware yet it implements swapping, then the memory manager will have to use a loader to recomputed the executable image from the absolute image. Would...
-
If you want to have 200,000 at the end of a 5 year period with 6% nominal interest compounded monthly. Jane does the first contribution at the end of the month assuming its the start of January. ...
-
Wedding Planners Limited (WP), owned by Anne and Francois Tremblay, provides wedding planning and related services. WP owns a building (the Pavilion) that has been custom-made for hosting weddings....
-
What best describes the revenue model for non-market nonprofit organizations?
-
What would achieving the vision of ending extreme income and multidimensional poverty look like, beyond raising minimum family income to above the poverty line to be able to buy basics? (To...
-
Why is a strictly economic definition of development inadequate? What do you understand economic development to mean? Can you give hypothetical or real examples of situations in which a country may...
-
What kinds of market failures are present in the economic self-discovery framework, and how may they be overcome?
-
In this chapter we have already been addressing some of the most basic questions for development economics. What is the real meaning of development? To what extent do the Sustainable Development...
-
What are some key similarities and differences between the SDGs and the earlier MDGs?
-
Addressing Table Device R-B-10 WLC-10 Admin LT-1 laptop RADIUS server Instructions G0/0/0.10 G0/0/0.100 G0/0/0.172 Interface management WLAN 10 NIC NIC NIC Address and Prefix 192.168.10.1/24...
-
Given that all the choices are true, which one concludes the paragraph with a precise and detailed description that relates to the main topic of the essay? A. NO CHANGE B. Decades, X-ray C. Decades...
-
Use the first thirteen rules of inference to derive the conclusions of the following symbolized arguments: 1. ~S /~(F.S)
-
Use the eighteen rules of inference to derive the conclusions of the following symbolized arguments. 1. F (A.K) 2. G (~A~K) 3. FVG / A=K
-
All currently living dinosaurs are giant reptiles. All giant reptiles are ectothermic animals. Therefore, some ectothermic animals are currently living dinosaurs. Use Venn diagrams to determine...
-
The temporary account used only in the closing process to hold the amounts of revenues and expenses before the net difference is added or subtracted from the owners capital account is called the a....
-
Refer to Circuit Citys balance sheet in Appendix A Identify the accounts listed as current liabilities. Consolidated Balance Sheets $ in millions, except per share amounts Asset Current Assets Cash...
-
Determining effects of closing entries Gloriosa Company began the current period with a \($28,000\) credit balance in the M. Gloriosa, Capital account. At the end of the period, the companys adjusted...
Study smarter with the SolutionInn App