|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object pt.tumba.cage.MathEvaluator
public class MathEvaluator
A Mathematic expression evaluator. Currently, the following functions are supported:
+, -, *, /, ^, %,
cos, sin, tan, acos, asin, atan,
sqrt, sqr, log,
min, max, ceil, floor, abs, neg, rndr.
When the method getValue()
is called, a Double object is returned.
If it returns null, an error occured while parsing the expression.
Sample: MathEvaluator m = new MathEvaluator("-5-6/(-2) + sqr(15+x)"); m.addVariable("x", 15.1d); System.out.println( m.getValue() );
Constructor Summary | |
---|---|
MathEvaluator()
Constructor for creating an empty MathEvaluator. |
|
MathEvaluator(java.lang.String s)
Constructor for Creating a MathEvaluator and assigning a math expression string. |
Method Summary | |
---|---|
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 method, used to run the program in command line. |
void |
reset()
Resets the evaluator. |
void |
setExpression(java.lang.String s)
Sets the expression to evaluate. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public MathEvaluator()
public MathEvaluator(java.lang.String s)
s
- A String with the math expression.Method Detail |
---|
public static void main(java.lang.String[] args)
args[]
- The command line input, tokenized.public void addVariable(java.lang.String v, double val)
v
- A String with the variable name.val
- the value for the variable.public void addVariable(java.lang.String v, java.lang.Double val)
v
- A String with the variable name.val
- the value for the variable.public java.lang.Double getValue()
public java.lang.Double getVariable(java.lang.String s)
v
- A String with the variable name.
public void reset()
public void setExpression(java.lang.String s)
s
- A String with the expression to evaluate.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |