public class MathEvaluator
extends java.lang.Object
Sample: MathEvaluator m = new MathEvaluator("-5-6/(-2) + sqr(15+x)"); m.addVariable("x", 15.1d); System.out.println( m.getValue() );
Constructor and Description |
---|
MathEvaluator()
creates an empty MathEvaluator.
|
MathEvaluator(java.lang.String s)
creates a MathEvaluator and assign the math expression string.
|
Modifier and Type | Method and Description |
---|---|
void |
addVariable(java.lang.String v,
double val)
adds a variable and its value in the MathEvaluator
|
void |
addVariable(java.lang.String v,
java.lang.Double val)
adds a variable and its value in the MathEvaluator
|
java.lang.Double |
getValue()
evaluates and returns the value of the expression
|
java.lang.Double |
getVariable(java.lang.String s)
gets the variable's value that was assigned previously
|
static void |
main(java.lang.String[] args)
Main.
|
void |
reset()
resets the evaluator
|
void |
setExpression(java.lang.String s)
sets the expression
|
void |
trace()
trace the binary tree for debug
|
public MathEvaluator()
public MathEvaluator(java.lang.String s)
public static void main(java.lang.String[] args)
public void addVariable(java.lang.String v, double val)
public void addVariable(java.lang.String v, java.lang.Double val)
public java.lang.Double getValue() throws java.lang.Exception
java.lang.Exception
public java.lang.Double getVariable(java.lang.String s)
public void reset()
public void setExpression(java.lang.String s)
public void trace()