Class myArithmetic

java.lang.Object
  extended by myArithmetic

public class myArithmetic
extends java.lang.Object

The myArithmetic class receives an arithmetic expression in the form of a String and evaluates it. For example, if the class receives the String "5-4-3" it prints the result -2.


Constructor Summary
myArithmetic()
          The constructor allocates memory for the two ArrayStack objects that the class employs.
 
Method Summary
 java.lang.String doCalculation(java.lang.String firstS, java.lang.String secondS, java.lang.String oper)
          performs the appropriate math and returns the result
 java.lang.String evaluateString(java.lang.String s)
          this main method of the class evaluates the arithmetic expression
 boolean isNumber(java.lang.String s)
          figures out if the parameter is a number
 boolean isOperator(java.lang.String s)
          figures out if the parameter is an operator
 boolean isSpace(java.lang.String s)
          figures out if the parameter is a space
static void main(java.lang.String[] args)
          main creates a myArithmetic object, calls the 'evaluateString()' method and prints the result
 int precedence(java.lang.String s)
          Returns the precedence of a given operator: ^ * / + -
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

myArithmetic

public myArithmetic()
The constructor allocates memory for the two ArrayStack objects that the class employs.

Method Detail

precedence

public int precedence(java.lang.String s)
Returns the precedence of a given operator: ^ * / + -

Parameters:
s - String whose precedence is to be determined
Returns:
the String's precedence (an int)

isOperator

public boolean isOperator(java.lang.String s)
figures out if the parameter is an operator

Parameters:
s - the String which may be an operator
Returns:
true if the parameter is an operator

isNumber

public boolean isNumber(java.lang.String s)
figures out if the parameter is a number

Parameters:
s - the String which may be a number
Returns:
true if the parameter is a number

isSpace

public boolean isSpace(java.lang.String s)
figures out if the parameter is a space

Parameters:
s - the String which may be a space
Returns:
true if the parameter is a space

doCalculation

public java.lang.String doCalculation(java.lang.String firstS,
                                      java.lang.String secondS,
                                      java.lang.String oper)
performs the appropriate math and returns the result

Parameters:
first - the first number in the calculation
second - the second number in the calculation
oper - the operator in the calculation
Returns:
a String that is the result of the calculation

evaluateString

public java.lang.String evaluateString(java.lang.String s)
this main method of the class evaluates the arithmetic expression

Parameters:
s - String to be evaluated
Returns:
the result of performing the calculation, in String form

main

public static void main(java.lang.String[] args)
main creates a myArithmetic object, calls the 'evaluateString()' method and prints the result