| | |
calculator program
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Mar 2006
Posts: 9
Reputation:
Solved Threads: 0
hai,
i need some help in developing a simple calculator!
i've finished the front-end part using jigloo software
but the problem is when i click the first number,that number will appear in the textfield after that when i click the '+' button the textfield is clearing but i'm not able able to read the entered value.
Also tell me where should i implement the logic to add these 2 numbers
i need some help in developing a simple calculator!
i've finished the front-end part using jigloo software
but the problem is when i click the first number,that number will appear in the textfield after that when i click the '+' button the textfield is clearing but i'm not able able to read the entered value.
Also tell me where should i implement the logic to add these 2 numbers
doesn't seem like a logical solution to me, but then I'm used to scientific calculators with built-in equation editors 
Create the entire equation as a single string and parse that using (for example) a recursive descent parser.
There's a nice book that does pretty much just that in one chapter called "the art of Java", then in the next chapter turns that calculator into a simplistic BASIC interpreter.

Create the entire equation as a single string and parse that using (for example) a recursive descent parser.
There's a nice book that does pretty much just that in one chapter called "the art of Java", then in the next chapter turns that calculator into a simplistic BASIC interpreter.
As people are clearly allowed to attack me but I'm not allowed to defend myself, I no longer post to this site.
try this:
1.user enter number
2a.user click operator
2b.set code to store number to a variable
2c.set code to store the status of the (last) operator click
3. user enters next numbers
4a. user clicks another operator button
4b. update stored variable (in step 2b, calculating the new value, depending on the operator used in step 2c)...
5...
there is still alot of gap to fill but i think its a good starting point... booleans and counters may be a good helps when writing the real code
--
fd
1.user enter number
2a.user click operator
2b.set code to store number to a variable
2c.set code to store the status of the (last) operator click
3. user enters next numbers
4a. user clicks another operator button
4b. update stored variable (in step 2b, calculating the new value, depending on the operator used in step 2c)...
5...
there is still alot of gap to fill but i think its a good starting point... booleans and counters may be a good helps when writing the real code
--
fd
http://www.java2s.com/ExampleCode/Sw...Calculator.htm
Looks a good example, haven't tried it though.
Assuming you know that basics about making a GUI and responding to User Input I don't see many problems.
Looks a good example, haven't tried it though.
Assuming you know that basics about making a GUI and responding to User Input I don't see many problems.
*Voted best profile in the world*
•
•
Join Date: Jun 2004
Posts: 2,108
Reputation:
Solved Threads: 18
•
•
•
•
Originally Posted by jwenting
doesn't seem like a logical solution to me, but then I'm used to scientific calculators with built-in equation editors
It would be nice to write an equation parse, because there could be some stumbling blocks somewhere in there. Most people would write a parenthesis balancer first, but do you really need it?
1 + (2-5)
should be the same as:
1 + (2-5
without the parenthesis
A simple equation like:
5*2+5*4/45
might not be that bad, but I think the parenthesis would get me.
>might not be that bad, but I think the parenthesis would get me.
I was wondering dat so I decided to do some research into it and build
one on the fly.
I think it can be done using syntax trees. Essentially, you have
to write your own grammer and parsing engine however, the idea would
be as follows:
For example if your expression is:-
/4+(17-5))
Then you would have your engine parse it into a syntax tree as follows:
Evaluting the expression recursively from the bottom upwards yields the
correct solution.
Most of what I learnt from the binary search tree was obtained from narue'
handy tutorial's www.eternallyconfuzzled.com
My binary tree syntax is a bit rusty in java so I did it in C, however, if I feel like it,
I might write one for java wen I get home from school. Tee he he.
Simple as pie kiddo.
I was wondering dat so I decided to do some research into it and build
one on the fly.
I think it can be done using syntax trees. Essentially, you have
to write your own grammer and parsing engine however, the idea would
be as follows:
For example if your expression is:-
Then you would have your engine parse it into a syntax tree as follows:
Java Syntax (Toggle Plain Text)
(+) / \ / \ / \ (*) (-) / \ / \ 3 (/) 17 5 / \ (+) 4 / \ 7 1
Evaluting the expression recursively from the bottom upwards yields the
correct solution.
Most of what I learnt from the binary search tree was obtained from narue'
handy tutorial's www.eternallyconfuzzled.com
My binary tree syntax is a bit rusty in java so I did it in C, however, if I feel like it,
I might write one for java wen I get home from school. Tee he he.
Simple as pie kiddo.
*Voted best profile in the world*
![]() |
Similar Threads
- C++ Calculator Program (C++)
- starting a calculator program in C (C)
- Java Swing Calculator program not running. It has 0 errors (Java)
- having problems to complete implement a simple calculator program in c (C)
- Wierd error messages with calculator program (C++)
- need hekp with C++ Calculator program (C++)
- need help with calculator program in C (C)
Other Threads in the Java Forum
- Previous Thread: Why illegal start of expression error?
- Next Thread: how to built an applet in java
Views: 5714 | Replies: 6
| Thread Tools | Search this Thread |
Tag cloud for Java
android api apple applet application apps arguments array arrays automation awt binary bluetooth businessintelligence busy_handler(null) card chat class classes client code collision component constructor database draw eclipse error event eventlistener exception file fractal game givemetehcodez graphics gui helpwithhomework html ide image input integer j2me jar java javafx javamicroeditionuseofmotionsensor javaprojects jmf jni jpanel jtree julia link linux list loop map method methods mobile netbeans newbie nls number object oracle parsing plazmic print problem program programming project recursion scanner screen server set sharepoint size smart sms socket sort sortedmaps sql string swing test textfield threads time transfer tree unlimited utility webservices windows






