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 Link icon

    Fields
    Modifier and Type
    Field
    Description
    static 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 Link icon

    Modifier and Type
    Method
    Description
    static Operator
    Return a known operator given its symbol, `op`.
    static boolean
    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`.
    Return the symbol used to represent this operator in expression strings.
  • Field Details Link icon

  • Method Details Link icon

    • operate Link icon

      double operate(double operand1, double operand2)
      Return the result of evaluating the operation on left operand `operand1` and right operand `operand2`.
    • symbol Link icon

      String symbol()
      Return the symbol used to represent this operator in expression strings. For example, the "plus" operator would have symbol "+".
    • fromString Link icon

      static Operator fromString(String op)
      Return a known operator given its symbol, `op`. Guaranteed to recognize "+", "-", "*", "/", "^".
    • isOperator Link icon

      static boolean isOperator(String symbol)
      Return whether `symbol` is a recognized operator symbol (i.e., one that could be passed to `fromString()`). Guaranteed to recognize "+", "-", "*", "/", "^".