|
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--com.ls.util.math.FormulaCalculator
This class performs calculation of a generic String expression (mathematic formula). The class is able to perform plus, subtract, multiply and divide. Considered rules: Multiplication and Division carried out before Addition and Subtraction. Brackets can be set and have a higher priority than the above rule. If necessary it takes the value of a formula-variable from a given Object Hashtable. If something goes wrong the class throws the FormulaCalculationException.
Constructor Summary | |
FormulaCalculator()
Default Constructor.. |
|
FormulaCalculator(int scale)
Constructor which sets the scale to which results are set. |
Method Summary | |
BigDecimal |
calculateEquation(String equation)
Calculating the given equation (formula). |
BigDecimal |
calculateEquation(String equation,
Hashtable values)
Calculating the given equation (formula). |
int |
getScale()
Returns the currently set scale. |
static void |
main(String[] args)
Only for testing purposes. |
void |
setScale(int scale)
Set the scale to which results are set. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public FormulaCalculator(int scale)
scale
- - the scale to which results are set.public FormulaCalculator()
Method Detail |
public BigDecimal calculateEquation(String equation) throws FormulaCalculationException
equation
- - a String which represents the equationFormulaCalculationException
- If something went wrongpublic BigDecimal calculateEquation(String equation, Hashtable values) throws FormulaCalculationException
equation
- - a String which represents the equationvalues
- - a Hashtable which contains the needed values to substitute the variables in the equation.FormulaCalculationException
- If something went wrongpublic void setScale(int scale)
scale
- - the scale to which results are set.public int getScale()
public static void main(String[] args)
args
- the scale to which results are set.
|
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |