/** * This represents the operator - in an arithmetic equation; as in 3 - 5 = -2. * * @author Will Holcomb */ public class SubtractionOperator extends Operator { /** * Creates an {@link Operator} with: * */ public SubtractionOperator() { token = new String("-"); precedence = 3; numberOperands = 2; preceededByAnOperand = true; } /** * @param x[] the operands * @return x[0] - x[1] */ public int operate(int [] x) { int solution; if(x.length == numberOperands) solution = x[0] - x[1]; else { System.out.println("Error in \"" + token + "\""); solution = 0; } return solution; } }