In class, we went over basic postfix expressions and an approach for evaluating them. The Java code was likewise presented and is available in Canvas. You are to enhance this code (or start from scratch if you prefer) and include a number of additional functions. A basic rubric is also presented which specifies the functionality required to get the desired grade.
My recommendation is that you proceed in the order specified to improve your grade while managing your time and effort. Your Java program will continue to prompt the user for additional expressions until the user chooses to finish (as the current source code does).
In addition to the two provided classes (PostfixTester and PostfixEvaluator), you must create and use a TooManyOperandsException exception class and may create additional classes to complete your solution. The main() must be in PostfixTester. Create a robust solution by catching any exceptions that may occur during your evaluation.
The program should handle the exception gracefully and report the error (See example, below) Specifically, you should catch: 1. The number of operands required for the operation are not available.
For example: 5 + 2. The number of values remaining on the stack after the expression has been consumed is greater than 1. For example: 1 2 3 + For case 1, java.util.Stack should throw an exception for you to catch and handle in PostfixTester, although you are welcome to create your own exception if you prefer. For case 2, you must create a TooManyOperandsException exception class, throw this exception from PostfixEvaluator when this condition occurs, then catch and handle it in PostfixTester.
Get Free Quote!
408 Experts Online