Question
UMUC CMSC 350 Project 1 1. Specification The first programming project involves writing a program that converts prefix expressions to postfix and postfix expressions to
UMUC CMSC 350 Project 1
1. Specification
The first programming project involves writing a program that converts prefix expressions to postfix and postfix expressions to prefix. Customary infix expression place the operator between the two operands. In a prefix expression, the operator comes before the two operands. In a postfix expression it comes after them. One benefit of prefix and postfix expressions is that they never require parentheses nor rules regarding precedence or associativity.
The program for this project should consist of three classes. The main class should create a GUI that allows the user to input an expression in either prefix or postfix and convert it to postfix or prefix, respectively. The GUI should look as follows (the same GUI is shown for each of the two conversions):
The GUI must be generated by code that you write. You may not use a drag-and-drop GUI generator. The second class should contain the code to perform the conversions. The pseudocode for prefix to postfix, which requires two stacks, is shown below:
tokenize the string containing the prefix expression while there are more tokens push the token onto an auxiliary stack if it is not a space while the auxiliary stack is not empty get the next token if it is an operand push it onto the operand stack else it is an operator pop two operands off of the operand stack create a string with the two operands followed by the operator push that string onto the operand stack pop the postfix expression off the operand stack
The pseudocode for the postfix to prefix conversion, which requires only one stack, is shown below:
tokenize the string containing the postfix expression while there are more tokens get the next token if it is a space skip it else if it is an operand push it onto the operand stack else it is an operator pop two operands off of the operand stack create a string with the operator followed by the two operands push that string onto the operand stack pop the prefix expression off the operand stack
Be sure to add any additional methods needed to eliminate any duplication of code.
The input expressions should not be required to contain spaces between tokens unless they are consecutive operands. The output expressions should always have a space between all symbols. The third class should be a custom checked exception SyntaxError. The exception should be thrown by the methods that perform the conversions if an empty stack is ever popped or the stack is not empty once the conversion is complete. The exception should be caught in the main class, where a JOptionPane window should be displayed containing an error message.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started