CMSC 350 Project 1 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...

1 answer below »
Create the java code for the project based on the exact requirements in the PDF document. Leave me instructions as to what I need to change/do in order to make sure the code runs. I attached the project document. If you need additional information, don't hesitate to reach out.


CMSC 350 Project 1 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 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 a reversal stack if it is not a space while the reversal stack is not empty pop the next token from the reversal stack 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 the operator push that string onto the operand stack pop the postfix expression off the 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 two operands push that string onto the operand stack pop the prefix expression off the 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. A checked exception SyntaxError 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. That exception should be 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. 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. Every outer class should be in a separate .java file with the same name as the class name. Each file should include a comment block at the top containing your name, the project name, the date, and a short description of the class contained in that file. 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 Grading Rubric Criteria Meets Does Not Meet Design 20 points 0 points GUI is hand coded and matches required design (4) GUI is generated by a GUI generator or does not match required design (0) Supplied algorithm is used (5) Supplied algorithm is not used (0) Code duplication is eliminated (3) Contains duplicated code (0) Contains separate class for expression conversion (4) Does not contain separate class for expression conversion (0) Contains checked exception class (4) Does not contain checked exception class (0) Functionality 60 points 0 points Correctly converts prefix to postfix (20) Does not correctly convert prefix to postfix (0) Correctly converts postfix to prefix (20) Does not correctly convert postfix to prefix (0) Correctly parses expressions without space delimiters (10) Does not correctly parse expressions without space delimiters (0) SyntaxError exception is thrown on expression with invalid syntax (5) SyntaxError exception is not thrown on expression with invalid syntax (0) SyntaxError is caught and a JOptionPane message is displayed (5) SyntaxError is not caught or a JOptionPane message is not displayed (0) Test Plan 10 points 0 points All operators included in test cases (3) Some operators not included in test cases (0) Test cases include expressions without spaces (3) Test cases don't include expressions without spaces (0) Test cases include cases that pop an empty stack (2) Test cases do not include cases that pop an empty stack (0) Test cases include cases which result in a non-empty stack (2) Test cases do not include cases which result in a non-empty stack (0) Documentation 10 points 0 points Correct UML diagram included (3) Correct UML diagram not included (0) Lessons learned included (4) Lessons learned not included (0) Comment blocks included with each Java file (3) Comment blocks not included with each Java file(0)
Answered 2 days AfterJan 17, 2021

Answer To: CMSC 350 Project 1 The first programming project involves writing a program that converts prefix...

Neha answered on Jan 20 2021
149 Votes
cmsc/DuplicateCode.java
cmsc/DuplicateCode.java
package cmsc;
import java.util.Stack;
// JavaProgram to check Code duplication
public class DuplicateCode {
public static boolean isDuplicate(String expression){
        if(expression==null)
            return false;
        char [] chars = expres
sion.toCharArray();
        Stack stack = new Stack<>();
        for (int i = 0; i             char c = chars[i];
            if(c==')'){
                int elements = 0;
                char x = stack.pop();
                while(x!='('){
                    elements++;
                    x = stack.pop();
                }
                if(elements<=1){
                    //If here means duplicate parenthesis are found,
 
                    return true;
                }
            }else
                stack.push(c);
        }
        return false;
    }
}
cmsc/MainActivity.java
cmsc/MainActivity.java
package cmsc;
import static cmsc.DuplicateCode.isDuplicate;
import static cmsc.PrefixToPostfix.PrefixToPostfixConversion;
import static cmsc.PostfixToPrefix.PostfixToPrefixConversion;
import java.awt.event.ActionEvent;
import java.util.EmptyStackException;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.WindowConstants;
/**
 * MainActivity for creating GUI that is used for converting prefix expressions to postfix 
 * and postfix expressions to prefix
 */
public class MainActivity extends JFrame {
  // Variables
  private String equation;
  private String result;
  // Constructs GUI
  private MainActivity() {
    // Set Title
    super("Expression Converter");
    // Create Panels
    JPanel main = new JPanel();
    JPanel inputPanel = new JPanel();
    JPanel evalPanel = new JPanel();
    JPanel resultPanel = new JPanel();
    // Set Layout
    main.setLayout(new BoxLayout(main, BoxLayout.Y_AXIS));
    // Create Components
    JLabel inputLabel = new JLabel("Enter Expression");
    JTextField inputTxt = new JTextField(null, 20);
    JButton evaluateBtn = new JButton("Prefix To Postfix");
    JButton evaluateBtn1 = new JButton("Postfix To Prefix");
    JLabel resultLabel = new JLabel("Result");
    JTextField resultTxt = new JTextField(null, 20);
    // Add Input Components
    inputPanel.add(inputLabel);
    inputPanel.add(inputTxt);
    // Add Evaluate Button
    evalPanel.add(evaluateBtn);
    evalPanel.add(evaluateBtn1);
    // Add Result Components
    resultPanel.add(resultLabel);
    resultPanel.add(resultTxt);
    resultTxt.setEditable(false);
    // Add Panels to main
    main.add(inputPanel);
    main.add(evalPanel);
    main.add(resultPanel);
    // Add main to JFrame
    add(main);
    // JFrame Settings
    setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    ...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here