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...
-
Navajo Companys financial statements show the following. The company recently discovered that in making physical counts of inventory, it had made the following errors: Inventory on December 31, 2012,...
-
Solve the problem of example 2.6 (page 54) by making use of the normal approximation to the hypergeometric distribution and compare with the exact result. Data from Example 2.6 A customer knows that...
-
A uniform fixed-fixed beam of length \(2 l\) is supported on a pin joint at the midpoint as shown in Fig. 8.38. Derive the frequency equation for determining the natural frequencies of vibration of...
-
You are considering three stocksA, B, and Cfor possible inclusion in your investment portfolio. Stock A has a beta of 0.80, stock B has a beta of 1.40, and stock C has a beta of 0.30. a. Rank these...
-
How does emotion regulation influence individuals' responses to conflict, and what techniques can be employed to cultivate emotional intelligence and self-awareness to facilitate constructive...
-
Gabi Gram started The Gram Co., a new business that began operations on May 1. The Gram Co. completed the following transactions during its first month of operations. May 1 G. Gram invested $40,000...
-
Perform a recruitment analysis for an organization to estimate the specific new talent requirements needed in the long and short term. Job in question: Sous Chef (3 5 years of experience) Prepare a...
-
What asset is used by watsonx.governance to organize all the models attempting to solve a single business problem?
-
Cash =$10,000,Contributed Capital =$35,000 Beginning Retained Earnings =$11,000, Dividends =$8,000 Revenues =$55,000, Accounts Payable =$15,000 Equipment =$40,000, Expenses =$33,000 What is the net...
-
A 22-year-old man presents to the Emergency Department with a painless ulcer affecting his glans penis. He admits to unprotected sexual intercourse with a man some two weeks earlier. There is no...
-
in paragraph 4, page 424. The situation mirrors the way we were once fitter-or, at least, leaner-when everyday life required more physical effort, in everything from shovelling coal into the furnace...
-
A company reported the following transactions. Journalize transactions that should be recorded in a purchases journal. March 4 Sold merchandise costing $ 1 , 2 2 0 to Lee for $ 3 , 1 0 0 on credit,...
-
Which is the correct association between the AMA's activity of marketing and the corresponding element of the marketing mix? Creating Promotion Communicating = Place = Delivering Product Exchanging...
-
What are the principal alloying elements in SAE 4340 steel?
-
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...
-
In May 2023 Bernard, a self-employed plumber, and his son Gerald, a self-employed electrician, purchased 1,000 empty barrels from a Scottish whisky distillery. The barrels were over 100 years old and...
-
Three brothers, Daniel, David and Derrick have been discussing their respective taxation affairs and how much they dislike paying tax. None of them are Scottish taxpayers. Daniel's income for tax...
-
On 6 August 2023, Danh (who is not a Scottish taxpayer) commenced self-employment as a sole trader. In addition, on 6 September 2023, he joined an existing partnership run by Ebele and Fai. The...
Study smarter with the SolutionInn App