Class Calculator

java.lang.Object
calculator.Calculator

public class Calculator extends Object
This class represents the core logic of a Calculator. It can be used to print and evaluate artihmetic expressions.
Author:
tommens
  • Constructor Details

    • Calculator

      public Calculator()
      Default constructor of the class. Does nothing since the class does not have any variables that need to be initialised.
  • Method Details

    • print

      public void print(Expression e)
      Prints an arithmetic expression provided as input parameter.
      Parameters:
      e - the arithmetic Expression to be printed
      See Also:
    • printExpressionDetails

      public void printExpressionDetails(Expression e)
      Prints verbose details of an arithmetic expression provided as input parameter.
      Parameters:
      e - the arithmetic Expression to be printed
      See Also:
    • eval

      public Atom eval(Expression e)
      Evaluates an arithmetic expression and returns its result
      Parameters:
      e - the arithmetic Expression to be evaluated
      Returns:
      The result of the evaluation
    • format

      public String format(Expression e, Notation notation)
      Formats an arithmetic expression in a given notation
      Parameters:
      e - the arithmetic Expression to be formatted
      notation - the notation to be used for formatting
      Returns:
      The formatted expression as a String