# CMSC 350 Project 1 Solved

30.00 \$

Category:
Click Category Button to View Your Next Assignment | Homework

You'll get a download link with a: . ` zip` solution files instantly, after Payment

## Description

The first programming project involves writing a program that evaluates infix expressions of unsigned integers using two stacks. The program should consist of three classes. The main class should create a GUI that allows the user input an infix expression and displays the result. The GUI should look as follows:

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 infix expression evaluation. The pseudocode for performing that evaluation is shown below:

tokenize the string containing the expression while there are more tokensÂ  get the next tokenÂ  Â Â Â Â  if it is an operandÂ  Â Â Â  Â Â Â Â  push it onto the operand stackÂ  else if it is a left parenthesisÂ  Â Â Â Â  push it onto the operator stackÂ  Â Â Â  else if it is a right parenthesisÂ  Â Â Â Â  Â Â Â Â  while top of the operator stack not a left parenthesisÂ  Â Â Â Â  Â Â Â Â  pop two operands and an operatorÂ  Â Â Â  Â Â Â Â  Â Â Â Â  perform the calculationÂ  Â Â Â Â  Â  Â Â Â Â  push the result onto the operand stack

else if it is an operator

while the operator stack is not empty andÂ  Â  Â Â Â Â  Â Â Â Â  the operator at the top of the stack has higherÂ  Â Â Â Â  Â Â Â Â  or the same precedence than the current operatorÂ  Â  Â Â Â Â  Â Â Â Â  pop two operands and perform the calculationÂ  Â Â Â Â  Â Â Â Â  push the result onto the operand stackÂ  Â Â  Â Â Â Â  push the current operator on the operators stack while the operator stack is not emptyÂ  Â  pop two operands and an operatorÂ  perform the calculationÂ  Â Â Â Â  push the result onto the operand stack the final result is a the top of the operand stack

Be sure to add any additional methods needed to eliminate any duplication of code.

Your program is only expected to perform correctly on syntactically correct infix expressions that contain integer operands and the four arithmetic operators + – * /. It should not, however, require spaces between tokens. The usual precedence rules apply. The division performed should be integer division. A check should be made for division by zero. Should the expression contain division by zero, a checked exception DivideByZero should be thrown by the method that performs the evaluation and caught in the main class, where a JOptionPane window should be displayed containing an error message.

• CMSC350P01.zip