COP-3337 Programming II
Programming Assignment 6
Knight Foundation School of Computing and Information Sciences
In this assignment, you implement a simple calculator supporting integer values with
only two operations addition and subtraction. The program receives an expression like
95 − XXXXXXXXXXfrom the keyboard and prints out the result (50 in this case) on the screen.
Please note that the input expression may include nested parentheses like
2 + (1 − XXXXXXXXXX − XXXXXXXXXX − 6))))
Therefore, your program needs to use the stack data structure (like java.util.Stack) to store
the intermediate results of inner parentheses and/or the operators.
1 Sample Input/Output
Here are some examples of how your program should operate:
input expression output
((2)) 2
−0022 −22
−(2 − 3 − 4) 5
XXXXXXXXXX
2 + (1 − XXXXXXXXXX − XXXXXXXXXX − 6)))) −9
1 + (2 − (3 + 4 − XXXXXXXXXX − XXXXXXXXXX − XXXXXXXXXX
2 Submissions
You need to submit a .zip file compressing the Java source file(s) of your program (.java
files).
1