import java.util.Scanner; /** * Simple calculator that reads infix expressions and evaluates them. * @author Dave Reed * @version 4/13/05 */ public class Calculator { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.print("Enter an expression (or hit RETURN to stop): "); String line = input.nextLine(); while (line.length() > 0) { Expression expr = new InfixExpression(line); if (expr.verify()) { System.out.println(expr.evaluate()); } else { System.out.println("INVALID EXPRESSION"); } System.out.print("Enter an expression (or hit RETURN to stop): "); line = input.nextLine(); } System.out.println("DONE"); } }