Best writers. Best papers. Let professionals take care of your academic papers

Order a similar paper and get 15% discount on your first order with us
Use the following coupon "FIRST15"
ORDER NOW

am having issue with spaces. Program crashes whenever a space

 am having issue with spaces. Program crashes whenever a space is

not implemented. Ex if I put 4*4 and not 4 * 4, the program crash. I also cannot get the program to calculate the numbers correctly whenever it involves ( ) such as ( 2 * 2 ) 2. The program crashes

InFix.javaimport java.uTl.EmptyStackExcepTon;import java.uTl.Stack;public class InFix{Stack<String> operandsStk;Stack<Character> operatorsStk;InFix(){operandsStk=new Stack<String>();operatorsStk=new Stack<Character>();}public int evaluate(String exp) throws ArithmeTcExcepTon{boolean fail=false;try{//±okenize the string containing the expression while there are more tokensString tokens[]=exp.split(” “);for(int i=0;i<tokens.length;i++)
Background image of page 01
{//if it is an operand push it onto the operand stackif(!tokens[i].equals(“+”)&& !tokens[i].equals(“*”)&&!tokens[i].equals(“-“)&&!tokens[i].equals(“/”) && !tokens[i].equals(“(“)&&!tokens[i].equals(“)”)){operandsStk.push(tokens[i]);}//else if it is a leF parenthesiselse if(tokens[i].equals(“(“)){//push it onto the operator stackoperatorsStk.push((Character)tokens[i].charAt(0));}//else if is a right parenthesiselse if(tokens[i].equals(“)”)){//while top of the operator stack not a leF parenthesiswhile(operatorsStk.peek()!='(‘){// pop two operands and an operatorint x=Integer.parseInt(operandsStk.pop());int y=Integer.parseInt(operandsStk.pop());
Background image of page 02

Show 

 
Looking for a Similar Assignment? Order now and Get 10% Discount! Use Coupon Code "Newclient"