// **** Imports **** import java.io.*; import java.util.*; /* * @Date: 7/28/2018 * @author James Brink, brinkje@plu.edu */ public class TrivialExample { double xVal, yVal, infixVal; String infix; ExprEvaluator evaluator = new ExprEvaluator(); Scanner scan = new Scanner(System.in); /** * Constructor for TrivialExample. * * Note: in this case, the expression only uses x and y. Hence the t * parameter is just set to 0 when evaluating the expression. */ public TrivialExample() { // get input System.out.print("Enter the value for x: "); xVal = scan.nextDouble(); System.out.print("Enter the value for y: "); yVal = scan.nextDouble(); scan.nextLine(); // read rest of line System.out.print("Enter the expression to be evaluated: "); infix = scan.nextLine(); // evaluate expression try { evaluator.buildFromInfix(infix); infixVal = evaluator.evaluate(0, xVal, yVal); // t = 0 System.out.println("x =" + xVal + ", y = " + yVal + ", expression = " + infixVal); } catch (Exception e) { System.out.println ("Error: namely: " + e); } } // constructor TrivialExample /** * Trivial main program that starts the application. */ public static void main (String args[]) { TrivialExample app = new TrivialExample(); System.exit(0); } // end main } // class TrivialExample