Computer Science II
PA 02
Fixing your "Simple Class" from PA01
and using the command line for testing It
Due by Monday, September 10th
[9:00 AM for code and paperwork]
Tasks
- Based on the feedback you received on your paperwork for PA01, and based
on in class discussions during Session 6 and Session 7, make the appropriate
modifications to your BoundedInteger.java class from PA01. Make sure
that all functionality is present and that all "design issues" are corrected.
- Create a new class called BoundedIntegerCLTest.java. This class is
designed to be a test of the mathematical operators that are part of
BoundedInteger and gets its "instructions" from the command line at run time.
Run time arguments are expected to follow these rules:
- The initial inputs set up the BoundedInteger to be tested.
- If three ints are provided, then the three parameter constructor for
BoundedInteger is to be used. If only two ints are provided, then the
two parameter constructor is to be used. You should assume that the
lower bound comes before the upper bound comes before the desired value.
- All additional parameters represent the test to be run on the
BoundedInteger. There are four valid flags for tests:
- -add, which should be immediately followed by a single int - the
parameter for the add() method
- -sub, which should be immediately followed by a single int - the
parameter for the subtract() method
- -inc, which should NOT be followed by an int since increment does not
use one.
- -dec, which should NOT be followed by an int since decrement does not
use one
- If the provided parameters are an illegal combination, an appropriate
error message should be generated.
Thus, the following are all legal invocations of this class
- java BoundedIntegerCLTest 10 20 15 -add 2
- java BoundedIntegerCLTest 10 20 -sub 20
- java BoundedIntegerCLTest 10 20 -dec
While the following are not
- java BoundedIntegerCLTest 10 20 10 20 -add 2
- java BoundedIntegerCLTest 10 20 -dec 2
- java BoundedIntegerCLTest 10 20 10 20 -add
There certainly are other cases and you will need to consider which are and
are not legal.
Challenge/Bonus
Modify BoundedIntegerCLTest.java so
that it can handle multiple commands provided at the command line.
For example,
- java BoundedIntegerCLTest 10 20 -add 2 -add 3 -sub 4
Would produce a BoundedInteger whose value is 10, then add 2 to get 12, then
add 3 to get 15, and then subtract 4 to get 11.
Once again, if the command is incorrect you should print an error message.
Deliverables
By the due date and time, submit the files
- BoundedInteger.java
- BoundedIntegerCLTest.java
Shortly after this, you will submit paper printouts of your code.
Be sure that your submission follows all
homework submission requirements.