*
The moose likes Java in General and the fly likes Need Help building Calculator Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Need Help building Calculator" Watch "Need Help building Calculator" New topic
Author

Need Help building Calculator

Muzafar Ali
Ranch Hand

Joined: Jun 11, 2009
Posts: 34
Hello,
I am building a 4 functions calculator program, it is accepting a number then at next line an Arithmetic Operator then at another line another number then show calculation on only single operator.
i need help to modify it to accept data like this
12 + 12 - 2 * 2 = 20 as wel or
100 / 2 + 200 = 250 i mean it have to perform calculation from all four operators on single line or two or three

here is a program which is getting input like this
12
+
12
24
that i don't want.


i shall wait for you answers !
if you have an example code for this pupose send me i will study from that.

regards,
Muzafar


~When You Learn Anything, Learn by Heart !
Eduardo Bueno
Ranch Hand

Joined: Jun 04, 2009
Posts: 155
Sorry but we are NotACodeMill. If you really did that code, you could easily do what you want just by looking at Scanner and String documentations.
Muzafar Ali
Ranch Hand

Joined: Jun 11, 2009
Posts: 34
Eduardo Bueno wrote:Sorry but we are NotACodeMill. If you really did that code, you could easily do what you want just by looking at Scanner and String documentations.

I know sir you are not a code mil,
i don't say that correct it as i say, i say that provide me sample which could work like that i shall study on that and after that i shall use that code in my program, you say that use Scanner and String documentation i will follow that now i shall study on those .

Thanks,
Muzafar
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38016
    
  22
If you are planning to use precedences, you need to look at a tutorial about parsing, convert the infix expression to postfix, and calculate in postfix.
Kalabaw moo
Ranch Hand

Joined: May 26, 2009
Posts: 61
You could implement a stack data structure to your program for the operands and the operators including the "(" ")" parenthesis. It would be simpler to evaluate a postfix expression than to an infix expression.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Need Help building Calculator
 
Similar Threads
Number calculations
[HOMEWORK] Please need help with java project
URGENT Help With Scientific Calculator!
So, which of these would be...