Package cs2110
Interface Operator
public interface Operator
Represents a binary arithmetic operator on real numbers. Interface also defines singleton
operators for common operations.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final OperatorOperator for addition.static final Stringstatic final OperatorOperator for division.static final Stringstatic final OperatorOperator for multiplication.static final Stringstatic final OperatorOperator for exponentiation.static final Stringstatic final OperatorOperator for subtraction.static final String -
Method Summary
Modifier and TypeMethodDescriptionstatic OperatorfromString(String op) Return a known operator given its symbol, `op`.static booleanisOperator(String symbol) Return whether `symbol` is a recognized operator symbol (i.e., one that could be passed to `fromString()`).doubleoperate(double operand1, double operand2) Return the result of evaluating the operation on left operand `operand1` and right operand `operand2`.symbol()Return the symbol used to represent this operator in expression strings.
-
Field Details
-
ADD_SYMBOL
- See Also:
-
SUBTRACT_SYMBOL
- See Also:
-
MULTIPLY_SYMBOL
- See Also:
-
DIVIDE_SYMBOL
- See Also:
-
POW_SYMBOL
- See Also:
-
ADD
Operator for addition. -
SUBTRACT
Operator for subtraction. -
MULTIPLY
Operator for multiplication. -
DIVIDE
Operator for division. -
POW
Operator for exponentiation.
-
-
Method Details
-
operate
double operate(double operand1, double operand2) Return the result of evaluating the operation on left operand `operand1` and right operand `operand2`. -
symbol
String symbol()Return the symbol used to represent this operator in expression strings. For example, the "plus" operator would have symbol "+". -
fromString
Return a known operator given its symbol, `op`. Guaranteed to recognize "+", "-", "*", "/", "^". -
isOperator
Return whether `symbol` is a recognized operator symbol (i.e., one that could be passed to `fromString()`). Guaranteed to recognize "+", "-", "*", "/", "^".
-