thisThis solution focusfocuses on the design of classes, not the actual push and pop stack part. I will include that part of the code as well. The current code has 2 operators (plus and minus). if we add another subclass under Token, is there a way that we don't need to check in processInput() what each operator is and perform the right calculation? I.
If we add another subclass under Token, is there a way that we don't need to check in
processInput()what each operator is and perform the right calculation?
I didn't know how to answer that question. I looked into Java Reflection, but still don't know how reflection can help me in this case. Can anyone shed some light on how I can make this design better? I
I want to allow people to add new operators, multiply and divide., and also maybe make their own definition for special operators/.
This application will take input string like "1 2 + 1 -" and output 2. because because "1 2 + 1 -" is the reverse Polish notation for (1+2)-1 = 2.