Question: ExpressionFactoryI.java: package expr; public interface ExpressionFactoryI { Expression add(Expression a, Expression b); Expression subtract(Expression a, Expression b); Expression multiply(Expression a, Expression b); Expression divide(Expression a,


ExpressionFactoryI.java:
package expr;
public interface ExpressionFactoryI {
Expression add(Expression a, Expression b);
Expression subtract(Expression a, Expression b);
Expression multiply(Expression a, Expression b);
Expression divide(Expression a, Expression b);
Expression constant(double value);
Expression x();
Expression sin(Expression a);
Expression cos(Expression a);
Expression tan(Expression a);
Expression ln(Expression a);
Expression exp(Expression a);
Expression parenthesized(Expression a);
}
Expression.java:
package expr;
public interface Expression {
double value( double x ) ;
}
Question 2: Expressions Composite and Abstract Fac- tory Pattenrs [30 marks] You will implement a set of immutable classes representing expressions in r, i.e., expressions with one free variable, r. Use at least one abstract class (with at least one abstract method) Your classes should be subtypes of the following interface expr.Expression. interface Expression double value (double x); Your classes should be able to represent expressions such as sin(2x + /2). Of course calling value(double) on an object representing this expression with an argument of say 0.39270 would give a value of 0.70711, which is sin(2 0.39270 + /2). Question 2: Expressions Composite and Abstract Fac- tory Pattenrs [30 marks] You will implement a set of immutable classes representing expressions in r, i.e., expressions with one free variable, r. Use at least one abstract class (with at least one abstract method) Your classes should be subtypes of the following interface expr.Expression. interface Expression double value (double x); Your classes should be able to represent expressions such as sin(2x + /2). Of course calling value(double) on an object representing this expression with an argument of say 0.39270 would give a value of 0.70711, which is sin(2 0.39270 + /2)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
