Assignment
4
Due
date: Monday
4/12/04 by 4:00pm
Hand
in electronically: POSCalculator.java,
questions.txt
Hand
in printed copies: POSCalculator.java
This
assignment requires you to write a class that reads from a file, does
calculations, and writes output to another file, handling exceptions along the
way. It’s much smaller than A3, but it
uses a lot of new ideas, so again, you can’t leave it to the last couple of
days and expect to finish. Here are
some things to remember:
1)
The
POSCalculator class must be instantiable. The main method may do the console I/O required to get filenames
from the user, but then it must create a POSCalculator object that does the
actual translating from one file to another.
So you will need a constructor, some data members, and a couple instance
methods.
2)
Since
you now know how to handle exceptions, your program should be unbreakable. Any exception that could occur should be
caught, and something reasonable should be done with it. The program may have to print an apology and
exit, but it should never crash.
3)
Remember
the correct Javadoc commenting style.
You don’t have to turn in a separate design for this one, but it would
be a good idea to start the same way that you had to for A3, with a comment
skeleton.
4)
This
hint will only make sense after you’ve read the assignment. Suppose you have a file that looks like
this:
1.0
+
2.5
=
You’ll be processing one
line at a time. When you read “1.0”, you don’t do anything right away, because
there’s
no calculation yet. But you’ll have to store the number 1.0 to
use later. When you read “+”, you know
what
operation you have to do
later, so you’ll have to store that knowledge.
When you read “2.5”, you finally have a
full operation, and you can
use the things you’ve stored along with the 2.5 to make the calculation. When you
read “=” you can print the
result of that calculation out.
Here’s the hint: remember that data members are where you
store the “state” of an object—information that
you’ll use later. This should give you an idea of some of the
data members you’ll need.