/* An instance of this class is a tree that represents a compound expression, ** meaning one involving at least one operator. ** ** Authors: R. McCloskey and < STUDENT's NAME > ** Date: Feb. 2022 ** Collaborated with: ... ** Known Defects: ... */ public class ExprTreeCompound extends ExprTree { // instance variables // ------------------ private String operator; // the represented expression's (binary) operator private ExprTree first; // the represented expression's first operand private ExprTree second; // the represented expression's second operand // constructor // ----------- /* Establishes this tree as one that represents an expression that ** is composed of the given operator together with its two operands ** (which are themselves given in the form of expression trees). */ public ExprTreeCompound(ExprTree first, String op, ExprTree second) { super(); this.first = first; this.second = second; this.operator = op; } // observers // --------- /* Returns the value of the expression represented by this tree, ** which is obtained by applying its operator to the values of its ** two operands. */ public int valueOf() { return 0; // STUB } /* Returns the expression-string describing the expression represented ** by this tree in the form specified by the given parameter, which is ** expected to be one of the inherited "print mode" values. If it is not, ** an IllegalArgumentException is thrown. */ @Override public String toString(int mode) { if (mode == PrefixMode) { return toStringPrefix(); } else if (mode == InfixMode) { return toStringInfix(); } else if (mode == PostfixMode) { return toStringPostfix(); } else { String errorMessage = " is not a legal mode"; throw new IllegalArgumentException(mode + errorMessage); } } // private methods // --------------- /* Returns the prefix form expression-string corresponding to this tree. */ private String toStringPrefix() { return "Gris"; // STUB! } /* Returns the postfix form expression-string corresponding to this tree. */ private String toStringPostfix() { return "Grop"; // STUB! } /* Returns the (fully-parenthesized) infix form expression-string ** corresponding to this tree. */ private String toStringInfix() { return "( " + first.toString(InfixMode) + ' ' + operator + ' ' + second.toString(InfixMode) + " )"; } }