package lab.art; /** * This class represents the average expression. * * @author Franck van Breugel */ public class Average extends BinaryExpression { /** * Initializes this average expression with the given two subexpressions. * * @param first the first subexpression. * @pre. first != null * @param second the second subexpression. * @pre. second != null */ public Average(Expression first, Expression second) { super(first, second); } /** * Evaluates this average expression at the given x- and y-coordinate. * * @param x the x-coordinate. * @pre. x >= -1 && x <= 1 * @param y the y-coordinate. * @pre. y >= -1 && y <= 1 * @return the value of this average expression at the given x- and y-coordinate. */ public double evaluate(double x, double y) { BinaryOperator average = new AverageOperator(); return super.evaluate(x, y, average); } /** * Returns a string representation of this average expression. * The string consists of "average(" followed by the string representation * of the first subexpression, followed by ", " followed by the * string representation of the second subexpression, followed by ")". * * @return string representation of this average expression. */ public String toString() { String pattern = "average(%s, %s)"; return super.toString(pattern); } }