I have to make a calculator in java that is able to work with brackets, plus, minus, divide and multiply, so far I've got it so if the user were to enter:
14 * ( 2 - ( 3 / 2 ) )
then it returns an ArrayList as:
[14.0, 2.0, 3.0, 2.0, /, -, *]
which is what i want
How do i then apply the '/' to the 2 and the 3 to get:
[14.0, 2.0, 1.5, -, *]
Then so on, so the '-' to the 2 and 1.5 to get:
[14.0, 0.5, *]
this carry's on to end up with a final answer of 7.0
Could anyone advise on how to do this?
Cheers for any help :)
You should only push numbers onto the stack. So operators don't go on the stack. This means the list goes:
Note that this means it's up to you to determine when numbers go on the stack and when operators are applied.