Question: Java Write a program FormatText that checks a text file for several formatting and punctuation matters and adjusts them to follow some style rules. The

Java

Write a program FormatText that checks a text file for several formatting and punctuation matters and adjusts them to follow some style rules.

The program asks for the names of both an input file and an output file.

It then copies all the text from the input file to the output file, but with the following two changes:

Any string of two or more blank characters is replaced by a single blank (if the first line starts with white space characters, remove them so the first line starts with a non-space character);

all sentences must start with an uppercase letter, including the first.

All sentences after the first one follow either a period, a question mark, or an exclamation point that is followed by one or more whitespace characters. Examples:

Blah. This is the start of a sentence. (period-space)

Blah.this is not the start of a sentence. (period but no space)

Hints: this is a difficult program!

Process the lines of the input file one character at a time using a for loop, and write out each appropriate character, maybe in upper case, using PrintStream print. At the end of each line do a println.

You can assume that whitespace characters are a space character, a tab character, \t, or a newline character, . Do not count an individual tab character or newline character as multiple spaces; that is, do not replace one of them with a single space, only do that if there are multiple whitespace characters side-by-side: in that case, just keep the first one of those characters and ignore the rest.

Treat the end of a line as a whitespace character, .

Use a boolean variable whitespace to track if youve seen a whitespace character so you can tell if there are multiple of them; reset it to false as soon as you see a non-whitespace character.

Use a boolean variable punctuation to track if youve seen a period, question mark, or exclamation point in order to check for a possible end of sentence.

Use a third boolean variable upperCase to indicate when the next character must be upper cased: when punctuation is true and the next character is whitespace (or end of line) set upperCase to true; always set punctuation to false on the next character. If upperCase is true, upper case the next non-whitespace character and set false.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!