Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a class ArithmeticExpressionEvaluator that evaluates an infix arithmetic e

ID: 3794282 • Letter: W

Question

Write a class ArithmeticExpressionEvaluator that evaluates an infix arithmetic expression. Do this is two steps. First, convert the infix expression to a postfix expression: create a filter InfixToPostfix that converts an arithmetic expression from infix to postfix. Second, evaluate the postfix expression: write a postfix evaluator Evaluate Postfix that takes a postfix expression, evaluates it and print the value. Your program should print the infix expression, postfix expression, and the final result.

Explanation / Answer

/*
* IteratorDemo.java
*
* Below program shows retrieving elements from Set implemented classes using Iterator
*/
import java.util.LinkedHashSet;
import java.util.Iterator;

public class IteratorDemo
{
   public static void main(String[] args) throws Exception
   {
       LinkedHashSet lhs = new LinkedHashSet();
      
       lhs.add(new Integer(10));
       lhs.add(new Integer(20));
       lhs.add(new Integer(30));
       lhs.add(new Double(40));
       lhs.add(new String("abc"));
       lhs.add(new Integer(10));

       Iterator lhsIterator = lhs.iterator();
       while(lhsIterator.hasNext())
       {
           Object ob = lhsIterator.next();
           System.out.println("Object :"+ob);

           //lhs.add("HARI"); // RE: CME   

           if(ob instanceof String)
           {
               String str = ((String)ob).concat("xyz");
               System.out.println("Modified String :"+str);              
  
           }
       }//while closed
   }
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote