Question Details

(Solved) paragraph formatting. I am currently doing my Ph.


this is computer science java program on For this assignment, you’re going to work on a task that is close to your instructor’s heart: paragraph formatting. I am currently doing my Ph. D. with lot of work on document engineering. Breaking paragraphs into lines is quite simple, but it has some tricky details that can make it challenging to program. Your program will read two files: a style file and a document file. The style file will be small and will contain a series of lines that define different styles for paragraphs. The document file will contain the text of a series of paragraphs. The style file gives parameters for formatting each of the paragraphs.

CompSci 251: Assignment 9
Due 5/1, 2017 10:00am
Topics Covered: Files, Exception Handling, Strings, Map 1 Introduction For this assignment, you’re going to work on a task that is close to your instructor’s heart: paragraph
formatting. I am currently doing my Ph. D. with lot of work on document engineering. Breaking paragraphs
into lines is quite simple, but it has some tricky details that can make it challenging to program. Your
program will read two files: a style file and a document file. The style file will be small and will contain a
series of lines that define different styles for paragraphs. The document file will contain the text of a series
of paragraphs. The style file gives parameters for formatting each of the paragraphs. 2 Requirements There are three main classes. The ParaStyle class just holds values for paragraph styles. Each style has a
name and three integer values. “lineLength” specifies the total number of characters in each line, including
any spaces for indentation and between words. “leftIndent” specifies how many blank spaces appear on
the left of the line before the printing characters start. “firstLineAdjustment” specifies how the first line is
different from the leftIndent in the number of blank spaces at the start of the line for each paragraph. In
theory, there should be constraints on these three values. firstLineAdjustment can be negative and when
you add it and leftIndent, the value should always be non-negative. leftIndent and lineLength must be
nonnegative. lineLength for practical reasons should never be less than about 30 characters and leftIndent
should never be higher than about 15. We will ignore these issues. In other words, you don’t have to check
that ParaStyle objects follow these rules. We’re just telling you so that you know that a production system
would probably have to do something about them.
The Paragraph class holds a String (just one String, not an array of Strings). It is designed so that the
text of the paragraph can be read from a series of lines in a file, with the program adding each line to the
Paragraph object as the line is read in. Once the Paragraph is complete, it will contain all of the text of
the paragraph as a single line, with at least one space between each word. Then, it can be formatted by
calling the format method. The format method requires a ParaStyle object and it returns a String with the
paragraph broken into lines in the format specified by the ParaStyle.
The ParagraphDriver class reads a set of ParaStyle specifications from one file and a document that contains
a series of Paragraphs from another file. It writes the paragraphs formatted correctly to an output file. 1 Here are UML class diagrams:
ParaStyle
- name : String
leftIndent : int
lineLength : int
firstLineAdjustment : int + ParaStyle(name : String, leftIndent : int, lineLength : int, firstLineAdjustment : int)
//add accessors and mutators and toString as necessary Paragraph
- words : String
+ Paragraph()
+ addWords(moreWords : String) : void
+ format(ps: ParaStyle) : String
//You can add other helper methods as you find them useful ParagraphDriver
+ static main(String[ ] args) : void
+ static readStyles(styleScanner : Scanner) : Map<String, ParaStyle>
+ static formatDocument(documentScanner : Scanner, outputFileWriter : PrintWriter,
styles : Map<String, ParaStyle>) : void 2 3 Errors and Exception Handling Your program must use exception handling for FileNotFoundExceptions. You may choose to create other
Exception classes if that’s helpful. Your program should print error messages to the console for the following
errors:
• An input or output file can’t be opened. In this case, the program should halt. 4 Sample Output I have made a file containing a text about the “Red Rose City (Petra)”. I also have two files with style
information and the two output files that result. It’s not a realistic specification of styles, but these make
fine examples for testing. NOTE: Your program must work as specified above. The TA whose in charge for
grading this assignment may test your program with different input files from what I am giving you. The
document file has a simple structure. Each paragraph begins with a line that specifies what style will be
used for that paragraph in the format “.P style-name”. You can assume
• that this “.P” line will start with the dot and that there will only be one space after the “.P”.
• that every paragraph style that is specified on a “.P” line will actually match a style in the style file.
• that every paragraph will have at least one line of text after the “.P” line.
The style file contains a series of lines that specify a paragraph style. Each line has a style name, the number
of spaces for leftIndent, the maximum number of characters per line, and the number of characters for the
first line adjustment to leftIndent. You can assume that every line has exactly these four values and that
there will not be any number format errors in the file. This means that you can use the ”next” and “nextInt”
methods of the Scanner to read in the values. Using “nextLine” will be more complicated.
Sample Run 1
Welcome to the Document Formatter!
Enter Style filename: style1.txt
Enter Document filename: petra.txt
Enter output filename: output1.txt
Goodbye!
Sample Run 2
Welcome to the Document Formatter!
Enter Style filename: style2.txt
Enter Document filename: petra.txt
Enter output filename: output2.txt
Goodbye!
Sample Run 3
Welcome to the Document Formatter!
Enter Style filename: style3.txt
Couldn’t open style file: style3.txt (No such file or directory)
Goodbye!
Initial Content of style1.txt, style2.txt, and petra.txt
Text in
para1 0
para2 5
para3 5 style1.txt
70 0
65 5
70 -3 3 Text in style2.txt
para1 5 40 0
para2 0 50 5
para3 10 60 -4
Text in “petra.txt”
.P para1
Deep within the deserts of Jordan lies the ancient city of Petra.
Through a narrow gorge it emerges into view, revealing awe-inspiring
monuments cut into the surrounding cliffs. What is this astonishing city?
Who built it, and why?
.P para2
Two thousand years ago, Petra stood at a crossroads of the ancient Near East.
Camel caravans passed through, loaded with spices, textiles and incense from distant
regions--and through such commerce, the city flourished. Its people, the Nabataeans,
harnessed precious water, enabling the population to soar to perhaps 20,000.
.P para3
Re-discovering this astounding complex of cliff-carved faades as Swiss explorer,
Johann Ludwig Burckhardt, did exactly 200 years ago must surely have been well worth
writing home about. Now well known to the world - in no small part due to its on-screen
role in ’Indiana Jones and the Last Crusade’ - and in company with the likes of Cambodia’s
Angkor Wat, Peru’s Machu Picchu, and the Great Wall of China on the list of New 7 Wonders
of the World, it is thrilling to imagine what this intrepid explorer must have felt on
first seeing Petra.
Expected content of “output1.txt” after running sample Run 1
Deep within the deserts of Jordan lies the ancient city of Petra.
Through a narrow gorge it emerges into view, revealing awe-inspiring
monuments cut into the surrounding cliffs. What is this astonishing
city? Who built it, and why?
Two thousand years ago, Petra stood at a crossroads of
the ancient Near East. Camel caravans passed through, loaded
with spices, textiles and incense from distant regions--and
through such commerce, the city flourished. Its people, the
Nabataeans, harnessed precious water, enabling the
population to soar to perhaps 20,000.
Re-discovering this astounding complex of cliff-carved faades as
Swiss explorer, Johann Ludwig Burckhardt, did exactly 200 years
ago must surely have been well worth writing home about. Now well
known to the world - in no small part due to its on-screen role
in ’Indiana Jones and the Last Crusade’ - and in company with the
likes of Cambodia’s Angkor Wat, Peru’s Machu Picchu, and the
Great Wall of China on the list of New 7 Wonders of the World,
it is thrilling to imagine what this intrepid explorer must have
felt on first seeing Petra.
Expected content of “output2.txt” after running sample Run 2
Deep within the deserts of Jordan
4 lies the ancient city of Petra.
Through a narrow gorge it emerges
into view, revealing awe-inspiring
monuments cut into the surrounding
cliffs. What is this astonishing
city? Who built it, and why?
Two thousand years ago, Petra stood at a
crossroads of the ancient Near East. Camel
caravans passed through, loaded with spices,
textiles and incense from distant regions--and
through such commerce, the city flourished. Its
people, the Nabataeans, harnessed precious water,
enabling the population to soar to perhaps 20,000.
Re-discovering this astounding complex of cliff-carved
faades as Swiss explorer, Johann Ludwig
Burckhardt, did exactly 200 years ago must surely
have been well worth writing home about. Now well
known to the world - in no small part due to its
on-screen role in ’Indiana Jones and the Last
Crusade’ - and in company with the likes of
Cambodia’s Angkor Wat, Peru’s Machu Picchu, and
the Great Wall of China on the list of New 7
Wonders of the World, it is thrilling to imagine
what this intrepid explorer must have felt on
first seeing Petra. 5

 


Solution details:
STATUS
Answered
QUALITY
Approved
ANSWER RATING

This question was answered on: Sep 05, 2019

PRICE: $18

Solution~000200163318.zip (25.37 KB)

Buy this answer for only: $18

This attachment is locked

We have a ready expert answer for this paper which you can use for in-depth understanding, research editing or paraphrasing. You can buy it or order for a fresh, original and plagiarism-free solution (Deadline assured. Flexible pricing. TurnItIn Report provided)

Pay using PayPal (No PayPal account Required) or your credit card . All your purchases are securely protected by .
SiteLock

About this Question

STATUS

Answered

QUALITY

Approved

DATE ANSWERED

Sep 05, 2019

EXPERT

Tutor

ANSWER RATING

GET INSTANT HELP/h4>

We have top-notch tutors who can do your essay/homework for you at a reasonable cost and then you can simply use that essay as a template to build your own arguments.

You can also use these solutions:

  • As a reference for in-depth understanding of the subject.
  • As a source of ideas / reasoning for your own research (if properly referenced)
  • For editing and paraphrasing (check your institution's definition of plagiarism and recommended paraphrase).
This we believe is a better way of understanding a problem and makes use of the efficiency of time of the student.

NEW ASSIGNMENT HELP?

Order New Solution. Quick Turnaround

Click on the button below in order to Order for a New, Original and High-Quality Essay Solutions. New orders are original solutions and precise to your writing instruction requirements. Place a New Order using the button below.

WE GUARANTEE, THAT YOUR PAPER WILL BE WRITTEN FROM SCRATCH AND WITHIN YOUR SET DEADLINE.

Order Now