|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||
java.lang.ObjectmyArithmetic
public class myArithmetic
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 |
|---|
public myArithmetic()
| Method Detail |
|---|
public int precedence(java.lang.String s)
s - String whose precedence is to be determined
public boolean isOperator(java.lang.String s)
s - the String which may be an operator
public boolean isNumber(java.lang.String s)
s - the String which may be a number
public boolean isSpace(java.lang.String s)
s - the String which may be a space
public java.lang.String doCalculation(java.lang.String firstS,
java.lang.String secondS,
java.lang.String oper)
first - the first number in the calculationsecond - the second number in the calculationoper - the operator in the calculation
public java.lang.String evaluateString(java.lang.String s)
s - String to be evaluated
public static void main(java.lang.String[] args)
|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||