//******************************************************************************
********************************
// CLASS: AddOperator
//
// AUTHOR
// 
// Computer Science & Engineering Program
// Fulton Schools of Engineering
// Arizona State University, Tempe, AZ 85287-8809
// http://www.devlang.com
//******************************************************************************
********************************
/**
* Represents the addition operator which is a specific type of binary operator.
*/
public class AddOperator extends BinaryOperator {
public AddOperator() {
}
/**
* Returns the sum of the left-hand side operand and the right-hand side
operand.
*/
@Override
public Operand evaluate(Operand pLhsOperand, Operand pRhsOperand) {
return new Operand(pLhsOperand.getValue() + pRhsOperand.getValue());
}
/**
* Returns the normal precedence level of this operator.
*/
@Override
public int precedence() {
return 2;
}
/**
* Returns the precedence level of this operator when on it is on the
operator stack.
*/
@Override
public int stackPrecedence() {
return 2;
}
}

    • 11 years ago
    the answer 100 % correct answer. in java
    NOT RATED

    Purchase the answer to view it

    • src.zip