/** A class for testing the manipulation of algebraic expressions */ import java.util.*; public class A5 { /** Tests a given algebraic expression by converting it to postfix and evaluating the expression. @param s the algebraic expression in infix form (tokens separated by spaces). */ public static void testExpression(String s) { System.out.println(s); Expression expr = new Expression(s); String p = expr.convertToPostfix(); System.out.println(p); try { System.out.println(expr.evaluate()); } catch (IllegalArgumentException e) { System.out.print("illegal expression -- "); System.out.println(e.getMessage()); } System.out.println(); } /** Perform the testing. @param args is ignored */ public static void main(String[] args) { Queue q = new Queue(); q.enqueue("hello"); q.enqueue("there"); q.enqueue("you"); System.out.println(q.isEmpty()); System.out.println(q.dequeue()); System.out.println(q.dequeue()); System.out.println(q.dequeue()); System.out.println(q.isEmpty()); System.out.println(); System.out.println(); testExpression("9"); testExpression("3 + 4"); testExpression(""); testExpression("+"); testExpression("3 4 5"); testExpression("3 + 4 5"); testExpression("3 +"); testExpression("3 + * 5"); testExpression("x + y - pi"); testExpression("3 + 4 * 5"); testExpression("3 * 4 + 5"); testExpression("3 + 4 * ) + 6"); testExpression("3 * 4 + 5 * 6"); testExpression("3 + 4 * 5 * 6"); testExpression("3 + 4 - 5 + 6"); testExpression("2 * 3 * 10 + 6"); testExpression("6 - 2 + 3 * 10"); testExpression("1 + 2 * 3 * 10 + 4"); testExpression("1 + 2 * 10 + 6 / 2"); testExpression("1 + 2 * 10 + 1 + 6 / 2"); } }