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 Operator
Operator for addition.static final String
static final Operator
Operator for division.static final String
static final Operator
Operator for multiplication.static final String
static final Operator
Operator for exponentiation.static final String
static final Operator
Operator for subtraction.static final String
-
Method Summary
Modifier and TypeMethodDescriptionstatic Operator
fromString
(String op) Return a known operator given its symbol, `op`.static boolean
isOperator
(String symbol) Return whether `symbol` is a recognized operator symbol (i.e., one that could be passed to `fromString()`).double
operate
(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
-
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 "+", "-", "*", "/", "^".
-