you can parse the String with the givn String functions. (indexOf,lastOf,split) But it is not that easy to write a algho who knows the mathematik.
I have done it once (without "()") but havnt the code to give it to you. 8[
I tell you what i have done:
I searched first for '*,/'
eg
input=120-20*2+30;
split the string at the givn index
left=120-20;
right=2+30;
at the left split i searcht the last +,- and on the right the first
split it again to the givn index
(leftRest=120;rightRest=+30)
now i take the left found Value -20 parse it to BigDecimal (because that will give u better results for comma values) and parse the right found Value to BigDecimal 2
now u can calculate
calcValue=-40=-20 * 2;
write the value back to the string, if the calcValue is not minus u have to write a + before; somting like this will do:
if(calcValue>0){
setPlus="+";
}else{
setPlus="";
}
input=leftRest+setPlus+Value+rightRest;
that give u:
120-40+30
now u repead until there are no *,/
then u start searching +,-
If u Divide somthing with bigDecimal u have to say how many comma values u like to have ... otherwise it will throw an exeption for thinks like 1/3
if u want to do it with '()' u have to split the string at '(',')' first and do the math within, then write it back without '()'
hope i could help you a little, i think there are other ways to do so, but i only need 6h, fully drunk do write this code ^^
Stefan