Write a simple text formatting program in java


Assignment:

Java Programming

Write a simple text formatting program in Java, that will read words from an input file and write them to an output file, removing extra whitespace and filling each line with as many words as will fit up to a maximum column width (similar to a column of text in a newspaper). The maximum column width, input text file name, and output text file name are entered interactively when the program starts.

The program needs to perform the following activities:

* Prompt for the maximum formatted output width. The range is 30 to 100 characters.

* Prompt for the file name of the input text file. Test that the file exists, and can be read. If so, then only open the file for reading. Repeat these steps until a valid input file is entered.

* Prompt for the file name of the output file to write the formatted words to. Test that the file does not already exist, and if it does, prompt to check for overwriting the file. Repeat these steps until a valid output file is entered.

* Write a line of * characters, the width of the formatted output, as a heading in the output file (no formatted output line should be longer than this heading line), for example, if 45 was entered as the maximum output width, this line should have 45 * characters.

* Read words (text between whitespace) from the input file, appending them to a line of text being formatted, with one space character between words. Keep appending words until the current word would cause the line to become longer than the output column width. If so, write the line to the output file, reset it to contain just the new word, and continue reading. Continue reading until the end-of-file is encountered.

part-1

Sample Output

Given the following input file:

The quick brown
fox jumped
over the big lazy brown

dog while
quickly running from the big bad wolf
across

the expansive rolling green
meadow towards the crumbling stone wall near
the waterfall.

Specifying a formatted output width of 30 should produce the following output:

Formatted output text follows...

******************************

The quick brown fox jumped over the big lazy brown dog while quickly running from the big bad wolf across the expansive rolling green meadow towards the crumbling stone wall near the waterfall.

Part-2

"Ode to 'Real' Programmers"

Real programmers don't do documentation.
Users should consider themselves lucky to get any programs at all,and take what they get.

Real
programmers
don't
comment
their
code.
If it was hard to write, it should be hard to understand.
Real programmers don't need comments - the code is obvious.

Real programmers don't eat quiche.
They eat twinkies,
M & M's,
Snickers, Ring-Dings,
and other healthful food.

Real programmers don't play tennis, or any other sport which requires youto change clothes.
Mountain climbing is OK, and real programmers wear their hiking boots towork in case a mountain should suddenly spring up in the middle of the room.

Real programmers don't wear neckties

Real programmer's programs never work the first time.
But if you throw them on the computer, they can be patched in only a few 30 hour debugging sessions.

Real programmers never work 9 to 5. If they are around at 9 A.M., its because they were up all night.

Real programmers don't write in Pascal, ADA, Bliss, or any of those silly 'strongly typed' languages.
Strong typing is for people with weak memories.

Real programmers arrive at work in time for lunch.

Part-3

Great Management Truths...

1. Have a plan.

Hip shooters die young.
Build your plans, and execute them in one straight, continuous line.

2. Be a realist.

Many plans might seem to lead to a happy never-never land of easy profit growth and tranquility for all.
Don't allow yourself or others to smoke this pipe.

3. Start with customer needs.
Your inventory will turn over a lot faster if it contains what people need.
Better yet if its also something they want.

4. Use your common sense.
It is simply astonishing how far a little common sense will go, and how seldom it is used.

5. Have an advantage.
If you don't have one, build one.
Otherwise, you will set dead in the water.

6. Recognize your limitations. Enthusiasm for your product and your company is important, but you will be marching steadily into a  swamp if you assume that everything you do is better than anything your competition does.
If you competitor has a lock on a particular piece of the market, recognize your limitations.

7. Establish objectives.
If you have nowhere to go, you will certainly get there.

8. Set your strategies.
You cannot be all things to all customers.
Fish where the fishing is best, and you will eat better than those who try to fish everywhere at once.

9. Execute well.
There are usually so many slips twixt cup and lip that an average plan, well executed, will beat out a better, but badly executed, plan every time.

10. Analyze.
If you don't analyze, you can't learn.
And if you don't learn, you won't grow.

Solution Preview :

Prepared by a verified Expert
JAVA Programming: Write a simple text formatting program in java
Reference No:- TGS01937832

Now Priced at $30 (50% Discount)

Recommended (90%)

Rated (4.3/5)