Question: PostfixEval.java. At first, limit the operations to add, subtract, multiply, and divide. If we require that every token in the input string is separated by
PostfixEval.java. At first, limit the operations to add, subtract, multiply, and divide. If we require that every token in the input string is separated by spaces, e.g., "33 -43 + -55 65 + *", we can evaluate decimals and negatives. Assume that the postfix string is well-formed. Use as test data the postfix expressions below. public static final String operators = "+ - * / % ^ !"; public static double eval(String str) { } public static double eval(double a, double b, String op) { } public static boolean isOperator(String op) { }
That is the assignment.
import java.util.*; public class PostfixEval { public static final String operators = "+ - * / % ^ !"; public static void main(String[] args) { System.out.println("Postfix --> Evaluate"); ArrayList postfixExp = new ArrayList(); /* build your list of expressions here */ for( String pf : postfixExp ) { System.out.println(pf + "\t\t" + eval(pf)); } } public static double eval(String pf) { List postfixParts = new ArrayList(Arrays.asList(pf.split(" "))); /* enter your code here */ } public static double eval(double a, double b, String ch) { } public static boolean isOperator(String op) { } } that is the shell code.
I am not understanding how to code the eval method and whever I try it always says nullPointerException,
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
