QuestionQuestion

Transcribed TextTranscribed Text

This 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 2 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. You are to submit two files. 1. The first is a .zip file that contains all the source code for the project, which includes any code that was provided. The .zip file should contain only source code and nothing else, which means only the .java files. If you elect to use a package the .java files should be in a folder whose name is the package name. 2. The second is a Word document (PDF or RTF is also acceptable) that contains the documentation for the project, which should include the following: a. A UML class diagram that includes all classes you wrote. Do not include predefined classes. You need only include the class name for each individual class, not the variables or methods b. A test plan that includes test cases that you have created indicating what aspects of the program each one is testing c. A short paragraph on lessons learned from the project

Solution PreviewSolution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use is strictly forbidden.

public class Project1 {

// Main method for program execution
public static void main(String[] args) {
   
    // Create main window frame
    String title = "Infix Expression Evaluator";
    JFrame frame = new JFrame(title);
   
    // Create JPanel containing entry of infix expression
    JPanel expressionPanel = new JPanel();
    expressionPanel.setLayout(new FlowLayout());
    JLabel enter = new JLabel("Enter Infix Expression");
    JTextField infixExpression = new JTextField(20);
    expressionPanel.add(enter);
    expressionPanel.add(infixExpression);
   
    // Create JPanel containing evaluate button
    JPanel buttonPanel = new JPanel();
    buttonPanel.setLayout(new FlowLayout());
    JButton evaluate = new JButton("Evaluate");
    buttonPanel.add(evaluate);
   
    // Create JPanel containing result of infix expression evaluation
    JPanel resultPanel = new JPanel();
    resultPanel.setLayout(new FlowLayout());
    JLabel result = new JLabel("Result");
    JTextField output = new JTextField(20);
    output.setText("0");
    output.setEditable(false);
    resultPanel.add(result);
    resultPanel.add(output);
   
    // Add Action Listener to act on Evaluate button click
    evaluate.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent ae) {
       InfixExpression expression = new InfixExpression(infixExpression.getText());
       try {
          output.setText(expression.evaluate());
       } catch (DivideByZero e) {
          JOptionPane.showMessageDialog(frame,"Error: Divide By Zero",
                                        "Error: Divide by Zero",JOptionPane.ERROR_MESSAGE);
       } catch (Exception e) {
          JOptionPane.showMessageDialog(frame,"Error: Invalid Input",
                                        "Error: Invalid Input",JOptionPane.ERROR_MESSAGE);
       }...

By purchasing this solution you'll be able to access the following files:
Solution.zip.

$60.00
for this solution

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available Java Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats