A common task in word processing is to reformat input text into a more structured format to match english grammar. For example, there should be a sinple space following a comma, two spaces following a period, and the first word in each sentence should be captilized. Furthermore, text can be aligned either left, right, center, or fully justified to look "better" when scanned down a page.

This assignment is to write a program that takes command line arguments for input file, output file, and formatting options then produce the output file based on formatting rules.

Part 1 - Spacing and Capitalization

All input text should be processed by the following rules:

  • there should be exactly one space between each word.
  • there should be exactly one space after a comma(,) before the next word. Do not insert spaces unless there is an additional word on the same line.
  • The word "i" (capital i), should always be captilized.
  • There should be exactly two spaces after a period (.), question mark(?), or exclamation point(!) before the next word. Do not insert spaces unless there is an additional word on the same line.
  • The first word in each sentence should be capitalized. This includes the first word in each paragraph and the first word after each period, question mark, or exclamation point.

Example Input: See image.

Issues: See image.

Text can also be left, right, center, or fully justified. Most text that you read is already left justified.

Input text: See image.

Output text justified to 33 columns(your code will justify to 72 columns)

Left Justified text: See image.

Right justified text: See image.

Center justified text: See image.

Fully justified text: See image.

Note that you should not line breaking or reduce spacing between words while performing justification. However, you are permitted to add or remove spaces at the start of each line and add additional spaces between words(for full justification). Your program should take a third argument to specify justification.

  • "-left": The first word on each line starts at column 0.
  • "-right": The last word on each line ends at column 72.
  • "-center": There are (approximately) an equal number of spaces at the beginning and end of each line.
  • "-full": The first word starts at column 0, the last ends at column 72, and intra-word spacing is approximately equal. Note that modern word processors don't applyy this to the last line in each paragraph(as above). However, this is not a requirement for your program.

Example command line usage:

Java Program3 input.txt output.txt -center
Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.