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.
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
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
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.
Joined: Mar 04, 2002
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