Question
import java.util.*; public class Evaluator { private Stack operandStack; private Stack operatorStack; private StringTokenizer tokenizer; private static final String DELIMITERS = +-*^/#! ; public Evaluator()
import java.util.*; public class Evaluator { private Stack
public class EvaluatorTester { public static void main(String[] args) { Evaluator evaluator = new Evaluator(); for ( String arg : args ) { System.out.format( "%s = %d ", arg, evaluator.eval( arg ) ); // System.out.println( arg + " = " + evaluator.eval( arg ) ); } } }
import javax.swing.*; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; public class EvaluatorUI extends JFrame implements ActionListener { private TextField txField = new TextField(); private Panel buttonPanel = new Panel(); // total of 20 buttons on the calculator, // numbered from left to right, top to bottom // bText[] array contains the text for corresponding buttons private static final String[] bText = { "7", "8", "9", "+", "4", "5", "6", "- ", "1", "2", "3", "*", "0", "^", "=", "/", "(", ")", "C", "CE" }; private Button[] buttons = new Button[ bText.length ]; public static void main(String argv[]) { EvaluatorUI calc = new EvaluatorUI(); } public EvaluatorUI() { setLayout( new BorderLayout() ); add( txField, BorderLayout.NORTH ); txField.setEditable( false ); add( buttonPanel, BorderLayout.CENTER ); buttonPanel.setLayout( new GridLayout( 5, 4 )); //create 20 buttons with corresponding text in bText[] array for ( int i = 0; i
public class Operand { public Operand( String token ) { } public Operand( int value ) { } public int getValue() { return 0; } public static boolean check( String token ) { return false; } }
public abstract class Operator { // The Operator class should contain an instance of a HashMap // This map will use keys as the tokens we're interested in, // and values will be instances of the Operators. // Example: // Where does this declaration go? What should its access level be? // Class or instance variable? Is this the right declaration? // HashMap operators = new HashMap(); // operators.put( "+", new AdditionOperator() ); // operators.put( "-", new SubtractionOperator() ); public abstract int priority(); public abstract Operand execute( Operand op1, Operand op2 ); public static boolean check( String token ) { return false; } }
Computer Science Department San Francis co State Univers ity CSC 413 Spring 2018 Assignment 1 - Expression Evaluator and Calculator GUI Note that the due date applies to the last commit times tamp into the main branch of your repository Overview The purpose of this assignment is to practice object oriented design to create two programs 1. An object that evahuates mathematical expressions 2. A GUI around the artifact from (1) Submis sion You are re quired to submit a documenta tion PDF which is to be stored in the documenta tion folder in your re pos itory, and provide your source code in the repository created in the github classroom The docume nta tion must inchide the following sections * Project introduction and overview (practice concisely summarizing technical work, and provide informa tion on execution and development environment). Inchude scope of work (what were you tasked with completing, what did you comple te) *Ins tructions to compile as jar and execute (you will be penalized if this is not provide d) *Assumptions (what assumptions did you make in order to complete the assignment) *Implementation discussion (I strongly recommend the use ofgraphical artif cts to heh describe your system and its implementation: class dia grams, hierarchy, etc Implementation decisions, code organization) *Results and conchsions (what did you learn, future work, what challenges did you encounter and how did you overcome them) Organization and appearance of this document is critical Please use spelling and grammar checkers - your ability to communicate about software and technology is almost as important as your ability to write software! Requirements You will be provided with an almost complete version of the Evaluator class (Evahiator.java). You should program the utility classes it uses - Operand and Operator and then follow the suggestions in the code to complete the imple mentation of the Evaluator class. The Evaluator implements a single public method, eval, that takes a single String parameter that represents an infx mathematicalexpression, parses and evaluates the expression, and returns the inte ger result. An example expression is 2 + 3 *4, which would be evahuated to 14
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