/* * @topic T10182 Feb 7, 2017 Inheritance Demo * @brief class BinaryOp is a subclass (derived class) */ package week03; public class BinaryOp extends BaseBinaryOp { //------------------------------ // data attributes //------------------------------ private int operation; //------------------------------ // constructors //------------------------------ public BinaryOp(int left, int right, int operation) { super( left, right ); this.operation = operation; }//BinaryOp //------------------------------ // operations //------------------------------ public void compute() { switch ( operation ) { case ADD: setResult( getLeft() + getRight() ); break; case SUBTRACT: setResult( getLeft() - getRight() ); break; default: // TODO: throw an exception } }//compute public int getOperation() { return operation; }//getOperation public void setOperation(int operation) { this.operation = operation; }//setOperation }//class BinaryOp