Forums Register Login

calculator question

+Pie Number of slices to send: Send
Can someone tell me how to cascade my calculator functions.
What I mean is:
If the user clicks 1 + 2 + 3 the output should be displayed as 6.
I have to press 1 + 2 = 3 + 3 to display 6.
Otherwise it will display 5 (the last two operands added).
Here is my source code.

[ March 07, 2002: Message edited by: Chad Moore ]
+Pie Number of slices to send: Send
Have you studied Finite State Machines yet?
Junilu
[ March 08, 2002: Message edited by: Junilu Lacar ]
+Pie Number of slices to send: Send
No ??
+Pie Number of slices to send: Send
No ??
The reason I asked is because a Calculator is normally implemented as a Finite State Machine. Other topics that would be good for you to know about are stacks and Reverse Polish Notation. This is obviously coursework so I was just wondering if FSMs and RPN is something that you have already encountered in your studies.
There are quite a number of things you can do to improve your program. I know this is not what you asked originally but IMO it would be well worth the effort to refactor your design before adding new functionality. When you do get around to adding new functionality you can do it easily and naturally.
Do you want to give it a shot? I'd be happy to step you through. But if you'd rather just get the lab work done, I'm sure others could suggest a quicker fix.
Junilu
+Pie Number of slices to send: Send
Hello,
I'm salivating at the prospect of learning some great design concepts. Chad, please accept the offer from Junilu or I'll have to post some really sloppy code to try and lure critique.
Good Luck,
-Dirk Schreckmann
+Pie Number of slices to send: Send
Hi Chad,
I can get you somewhere near (about 90%) using your existing code. I would just do the following three things:
1. Dump your result variable
2. Assign variable op1 Double.MAX_VALUE as a default and whenever we want to clear it.
3. Make better use of equalPressed boolean. You can use it for any operation pressed.
The code below gets really close.

Enjoy,
Manfred.
+Pie Number of slices to send: Send
Manfred, thanks for taking the time to look at and alter my code. Junilu, as Dirk stated, I would like to learn some programming concepts that will give me more programming skills. The calculator was already turned in, but I would still like to work on it more. It was a quite a learning experience, so I think it would help even more to continue with it. Being new to Java and OOP for that matter, I will take all the help I can get.
Thanks again
+Pie Number of slices to send: Send
Great! I'll start a thread in OO, Patterns, and Refactoring tonight so check it out there.
Junilu
[ March 09, 2002: Message edited by: Junilu Lacar ]
Ruth Stout was famous for gardening naked. Just like this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 1016 times.
Similar Threads
uses or overrides a deprecated API recompile with - deprection for details?
applet vs. program?
Stack Problem
Calculator Buttons
NullPointerException - Using JTextField to Add Numbers
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 09:40:21.