Question: 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


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.
Step by Step Solution
3.45 Rating (158 Votes )
There are 3 Steps involved in it
Text Parsing using Java Procedure WordStatistics class is defined with suggested variables and metho... View full answer
Get step-by-step solutions from verified subject matter experts
