Question: The expression evaluator in Section 13.5 returns the value of an expression. Modify the evaluator so that it returns an instance of the Expression interface
The expression evaluator in Section 13.5 returns the value of an expression. Modify the evaluator so that it returns an instance of the Expression interface with five implementing classes, Constant, Sum, Difference, Product, and Quotient. The Expression interface has a method int value(). The Constant class stores a number, which is returned by the value method. The other four classes store two arguments of type Expression, and their value method returns the sum, difference, product, and quotient of the values of the arguments. Write a test program that reads an expression string, translates it into an Expression object, and prints the result of calling value.
Step by Step Solution
3.35 Rating (155 Votes )
There are 3 Steps involved in it
To modify the expression evaluator to return an instance of the Expression interface you will need t... View full answer
Get step-by-step solutions from verified subject matter experts
