Package expression; public class calculate {public static boolean isoperator (string operator) {if (operator.equals) || operator.equals ("-") || Operator.Equals ("*") || Operator. Equals ("/") || Operator.equals (") || Operator.Equals (") ")) Return True; Else Return false;} public static int priorness (String operator) {ix (Operator.equals " ") || Operator.equals ("-") || Operator.Equals (")) Return 1; Else IF (Operator.Equals (" * ") || operator.equals (" / ")) Return 2; Else Return 0; PUBLIC STATIC STRING A, STRING B) {Try {String Op = Operator; String RS = New String (); double x = double.parsedouble (b); Double Y = Double.parsedouble (a); double z = 0; if (op.equals)) z = x y; Else IF (op.equals ("-")) z = xy; else ing .equals ("*")) z = x * y; else if (op.equals ("/"))) z = x / y; else z = 0; RETURN RS Z;} catch (NumberFormatexcection E) {system .out.println ("INPUT HAS Something Wrong!"); Return "Error";}}}
package expression; import java.util *;. public class Stacks {private LinkedList list = new LinkedList (); int top = -1; public void push (Object value) {top ; list.addFirst (value);} public Object pop () {Object Temp = list.getfirst (); TOP ---; list.removefirst (); return temp;
} Public object top () {return list.getfirst ();}}
package expression; import java.io *;. import java.util *;. public class Expression {private ArrayList expression = new ArrayList (); // in the program storage expression private ArrayList right = new ArrayList (); // store the right Programming Private String Result; / / The result // creates an object based on the input information, put the value and operator in arraylist (String INPUT) {StringTokenizer St = New StringTokenizer (Input, " - * / ()" , true (st.hasmorelements ()) {expression.add (st.nextToken ());}} // convert the middle order expression to the right sequence expression private void toright () {stacks ASTACK = New Stacks (); String operator; int position = 0; while {if (Calculate.isoperator ((string) Expression.get (position)) {if (Astack.Top == - 1 || Expression .get (")). Equals (")) {ASTACK.PUSH (Expression.get (position));} else {g ((String) Expression.get (position). Equals (")") ) {IF ASTACK.TOP ()). Equals (")) {Operator = (string) ASTACK.POP (); Right.Add (Operator);}} else {if (Calculate. Priority (String) Expression.get (position) <= Calculate.priority ((String) AST Ack.top ()) && Astack.top! = - 1) {Operator = (string) ASTACK.POP (); if (! operator.equals (")) Right.Add (Operator);} ASTACK.PUSH ( Expression.get (position));}}} Else right.add (expression.get (position)); position ; if (position> = expression.size ()) Break;} while (Astack.top! = - 1) {Operator = (String) ASTACK.POP (); Right.Add (Operator);}} // Review VOID GETRESULT ()} // {this.toright (); stacks astack = new stacks () ; String OP1, OP2, IS = NULL; Iterator IT = Right.iterator (); while (it.hasnext () {is = (string) it.next (); if (Calculate.IsoPerator (IS)) {OP1 =