Posts

Showing posts with the label hw7

CS3401 HW 7

package trees; /** Course: CS 3401  * Section: 01  * Name: Dalibor Labudovic  * Professor: Prof. Shaw  * Assignment #: Homework #7  */  import java.math.BigDecimal; import java.util.*; //******************************************************************** // Evaluates a given expression by first converting it to a // Postfix Stack and then to an Expression Tree and then // evaluating the Expression Tree //********************************************************************  public class EvaluateExpressionTree {  public static void main(String[] args) {  Scanner input = new Scanner(System.in);  System.out.println("Enter an equation in infix notation: " + "[Ex: 10+6/3 ]");  String expression = input.nextLine();  input.close();  try {  System.out.println("Result = " + evaluateExpressionTree(expression).stripTrailingZeros().toPlainString());  }  catch (Exception ex) {  System.out.println...