|
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--PostfixExpression | +--ArithmeticEquation
This class represents an arithmetic equation. For information on the storage method
see the constructor and
PostfixExpression.setEquation(ExpressionElementStack)
. For information about
how the solution is found, see PostfixExpression.solution()
.
Fields inherited from class PostfixExpression |
expression,
TESTING |
Constructor Summary | |
ArithmeticEquation(java.lang.String i)
The calculating for the initialization of this class is fairly complicated. |
Methods inherited from class PostfixExpression |
infixEquation,
setEquation,
solution,
toString |
Methods inherited from class java.lang.Object |
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
wait,
wait,
wait |
Constructor Detail |
public ArithmeticEquation(java.lang.String i)
AdaptedStringTokenizer
. The delimiters used in
the parse are the tokens from ArithmeticOperatorTable
and GenericGroupingSymbolTable
. The algorithm used
then is this:
- create a new stack of expression elements SE
- while(there are more tokens)
-
if the current token is an Operator
(as determined by the isAnOperator
function in
OperatorTable
)
push the appropriate Operator
onto SE
-
else if the current token is a
GroupingSymbol
(as determined by the GroupingSymbolTable.isAGroupingSymbol(String)
function in GroupingSymbolTable)
push the appropriate GroupingSymbol onto SE
-
else if the current token is a Integer
(as determined by the parseInt function
in Integer)
push the appropriate Integer onto SE
-
else consider the current token to be a Variable
push the approprate Variable onto SE
- Reverse SE
-
Call setEquation of
PostfixExpression with SE
After the while loop is through SE now contains all the information that was in the initial string,
but all of the information has been identified and pushed into a stack. The only problem is that in
the process of pushing it on the stack the order has been reversed, so the
ExpressionElementStack.reverse()
method
is called on SE and SE is sent to the PostfixExpression.setEquation(ExpressionElementStack)
of
the superclass to be converted and stored in postfix form.
i
- string representing an infox arithmetic equationPostfixExpression.setEquation(ExpressionElementStack)
|
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |