CSC407F Assignment #1
Page Breaker
Due: October 18 (in drop-off box by 5:00 p.m.)
Write a program in Java that takes as input an arbitrary text file
and outputs essentially the same file,
but with extra blank lines added in such a way that page-breaks
occur at convenient locations.
The command-line syntax you will use to execute your program is as follows.
java PageBreaker [-h] [-l lines] [-a algorithm]
-
Input should be read from stdin. The output should be sent to stdout.
-
The options may come in any order.
Any violation (or unrecognized option flags) result in a usage message
to stderr.
-
lines indicates how many lines your printer prints per page.
It is an optional argument and should default to a reasonable value.
-
algorithm indicates which of many potential algorithms
should be used in the page breaking.
It is an optional argument and should default to a reasonable value.
-
If the option -h is present, anything else on the command
line should be ignored, and an informative help message output
to stderr. The help message should list the names of all the
alternative algorithms you support, with a brief description
of each.
In deciding where to break pages, you should support at least the following
four algorithms.
- blanks
With this variant,
the number of blank lines in the input file determines the optimal
place to insert the page breaks.
You should associate "goodness" weights with 0 blank lines, 1 blank line,
2 blank lines, and so on.
You should associate "badness" weights with breaking the page 0 lines
before the end of the page, 1 line before the end of the page, and so on.
For every potential page break location on a page, you should
compute goodness - badness and break at the optimal point.
- indents
A similar approach to blanks but this time
you will break based on the location of indents and exdents.
Breaking at an indent will be considered a bad thing.
Breaking at a neutral point (no indent or exdent relative to the previous line)
will be considered a neutral thing.
Breaking at an exdent will be considered a good thing.
Breaking after multiple exdents will be better yet.
- bindent
A combination of blanks and indent.
- ???
Invent and name at least one of your own choosing.
An important consideration in your design should be the ability to
add new algorithms very easily, and to be able
to combine these algorithms. You should program with the view
of eventually being able to support the dynamic loading of new algorithms
and the ability to write a little expression in place of algorithm
that can combine loaded algorithms, although it is not necessary to
implement either of these features now.
Note that this task has many similarities to LEXI.
You should study that design for inspiration,
and consider the use of the patterns
Strategy, Abstract Factory, Iterator, and Visitor, amongst others.
You are to hand in the following work products:
- The location on the CDF system of your java program
so that the TA may execute it (N.B. It is your responsibility to ensure that
the TA can access and execute your java program - include all appropriate instructions. Failure to do so will result in a 0 for this part of the grade).
- A set of UML static class diagrams along with descriptions of all classes.
- Approximately one page of written text describing your design
(with reference to your UML)
indicating which patterns you have used,
and briefly discussing any design tradeoffs.
- Nicely formatted printouts of working Java code (with page breaks
at appropriate places, of course).
- Sample inputs and outputs that demonstrate your program works.
You will be marked based upon the following criteria (25% each):
- How well the program runs.
- The quality of your design.
- Your knowing use of patterns
(the more the better - you must explicitly point them out).
- The quality of your UML, writeup, source code, and test cases.
Note that if the quality of the UML, writeup, and/or source code
are so poor as to force the TA to dig to find the design and patterns,
you will receive low marks on the design and patterns portion as well.
Bonus
Two independent bonuses are available, each worth an absolute +5%.
- Implement dynamic loading of classes representing new algorithms.
- Implement an expression language for combining algorithms.
The bonuses will be marked on the same basis as the main assignment.