/**
* This represents the operator * in an arithmetic equation; as in 3 * 5 = 15.
*
* @author Will Holcomb
*/
public class MultiplicationOperator extends Operator
{
/**
* Creates an {@link Operator} with:
*
* - token: *
* - precedence: 2
* - numberOperands: 2
* - preceededByAnOperand: true
*
*/
public MultiplicationOperator()
{
token = new String("*");
precedence = 2;
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;
}
}