In this exercise, you will build a program to process files containing paragraphs. The aim of the program is to simply count the number of words and compute their length. The file, however, may contain numbers (e.g. "2018") and contains punctuation that should be ignored. There are two data files that you will use to test your program: shortpar.txt and cassini.txt. (1) Prompt the user to enter the name of a file. Store the text in a string and output the name of the file Now create the program to read the lines of the file, split each line into words, count the words and total their length. You should skip any numbers that are in the file and strip any punctuation from the words. Consider the following characters as punctuation , . ' : ; ? ! \ " ( ). Some of the words in the files may contain apostrophes (') but ignore them for this part of the exercise. For example, "NASA's" would be counted as a single word of length 6. You should print out the number of words and their average length The final step is to implement a function remove_apos() function, which has a string as a parameter, and returns a string with any apostrophes removed.in the string. These should be removed so that only the letters in a word are counted. For example, the word "NASA's" should be treated as "NASAs" and would have a length of 5

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter13: File Input And Output
Section: Chapter Questions
Problem 6PE
icon
Related questions
Question

In this exercise, you will build a program to process files containing paragraphs. The aim of the program is to simply count the number of words and compute their length. The file, however, may contain numbers (e.g. "2018") and contains punctuation that should be ignored.

There are two data files that you will use to test your program: shortpar.txt and cassini.txt.

(1) Prompt the user to enter the name of a file. Store the text in a string and output the name of the file

Now create the program to read the lines of the file, split each line into words, count the words and total their length. You should skip any numbers that are in the file and strip any punctuation from the words. Consider the following characters as punctuation , . ' : ; ? ! \ " ( ). Some of the words in the files may contain apostrophes (') but ignore them for this part of the exercise. For example, "NASA's" would be counted as a single word of length 6. You should print out the number of words and their average length

The final step is to implement a function remove_apos() function, which has a string as a parameter, and returns a string with any apostrophes removed.in the string. These should be removed so that only the letters in a word are counted. For example, the word "NASA's" should be treated as "NASAs" and would have a length of 5

For the file shortpar.txt, the output would be:
Enter name of file:
shortpar.txt
File to be processed is: shortpar.txt
The number of words is:
9.
The average length of a word is:
4.22
For the file cassini.txt, the output would be:
Enter name of file:
cassini.txt
File to be processed is:
cassini.txt
The number of words is:
231
The average length of a word is:
5.34
272806 1620374
Transcribed Image Text:For the file shortpar.txt, the output would be: Enter name of file: shortpar.txt File to be processed is: shortpar.txt The number of words is: 9. The average length of a word is: 4.22 For the file cassini.txt, the output would be: Enter name of file: cassini.txt File to be processed is: cassini.txt The number of words is: 231 The average length of a word is: 5.34 272806 1620374
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Knowledge Booster
File Input and Output Operations
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT