Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Assume one-or-more empty lines separate paragraphs in a text file. This homework requires you to develop a Java program that accepts 2 command-line arguments (i.e.,

Assume one-or-more empty lines separate paragraphs in a text file. This homework requires you to develop a Java program that accepts 2 command-line arguments (i.e., arguments to the main method):

1. The first command-line argument will be the path to the text file to be processed

2. The second command-line argument will be a Boolean flag (true or false). If this flag is false then word counts should simply be printed as zero. If this flag is true then word count must be computed and printed.

Print the first and last line (if different) of a paragraph in a given HTML format. Note that if first and last line is identical (i.e., a paragraph has only 1 line) then print just the first line.

Print count of words in each paragraph, if the second commandline argument is true. If you don't implement this functionality then just 0 (zero) as word count.

Tips:

The program is relatively straightforward. Use Scanner.nextLine() method to read lines from a text file.

For word count, create a Scanner for each line and use Scanner.next() to extract words

Sample text file input:

This is the first line of first paragraph

This is the second line of first paragraph

This is the third line of first paragraph

This is the last line of first paragraph

Second para line 1

Second para line 2

A one line third paragraph

This paragraph is going to have 5 lines. Line 1 of 5

This paragraph is going to have 5 lines. Line 2 of 5

This paragraph is going to have 5 lines. Line 3 of 5

This paragraph is going to have 5 lines. Line 4 of 5

This paragraph is going to have 5 lines. Line 5 of 5

This is the last, 1 line paragraph in this file.

Sample output:image text in transcribed

Example word count output: Note that the 2hd command-line argument is true. Hence, word counts should be reported. If you are not implementing valid English word counts, then print zero instead java Homeworkl base case.txt true First and last lineWord counts/tr> trtd>This is the first line of first paragraph This is the last line of first trtd>Second para line 1 Second para line 2/tdxtd>Words: 8 English words: trtd>A one 1line third paragraph X/td>xtd Words: 5 English words: 5Xtr> paragraph Words: 32 English words: 32K/td>Xtr> A This paragraph is going to have 5 lines. Line 1 of 5 This paragraph is going to have 5 lines. Line 5 of 5Words: 60 English words 45 This is the last, 1 line paragraph in this file.
Words: 10 English words:

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Concepts Of Database Management

Authors: Joy L. Starks, Philip J. Pratt, Mary Z. Last

9th Edition

1337093424, 978-1337093422

More Books

Students also viewed these Databases questions

Question

Briefly describe the five principles of succession planning.

Answered: 1 week ago