Package project2

Class Calculator

java.lang.Object
project2.Calculator

public class Calculator extends Object
A class that converts infix expressions to postfix expressions and evaluates postfix expressions. Uses the LinkedStack and ResizableArrayStack classes.
  • Constructor Details

    • Calculator

      public Calculator()
  • Method Details

    • convertToPostfix

      public <T> String convertToPostfix(String[] infix)
      Converts an infix expression to a postfix expression.
      Type Parameters:
      T - the type of the elements in the infix expression
      Parameters:
      infix - the infix expression
      Returns:
      the postfix expression
    • precedence

      public int precedence(String operator)
      Returns the precedence of an operator.
      Parameters:
      operator - the operator
      Returns:
      the precedence of the operator
    • evaluatePostfix

      public Integer evaluatePostfix(String postfix, Integer[] valuesArray, char[] characters)
      Evaluates a postfix expression.
      Parameters:
      postfix - the postfix expression
      valuesArray - the values of the variables in the expression
      characters - the characters in the expression
      Returns:
      the result of the expression
    • main

      public static void main(String[] args)
      Main method.
      Parameters:
      args - the command line arguments