Tuesday, September 25, 2007
Calculator How-To Using Java 2 Part 2
Today, I shall continue with the guide on Calculation How-To. In the previous part, we have discussed about the 4 fundamental steps to create this little calculator program.
Instead of scratching on the surface, I will go a bit deeper into the topic this time. I will not touch on the first 3 steps as I feel that it shouldn't be at your wits' end. Easy as pie I suppose! I will dive straight into the Step 4 and give you quite a handful of additional information that you will need in your development.
How a real calculator works (Implementation of Stack) -
The Program DesignI will be using 2 Stacks here. The first Stack is used to convert an infix expression to a postfix expression.
Well, an infix expression is something like 5 + 2 where the operator is in the center. Infix is the most commonly used expression taught in school. However, a postfix is something special. The operator is at the back. It is used by computers to evaluate results from certain expression.
Illustration of conversion between the infix and the postfix expression below:

An algorithm has to be used for this kind of conversion. You can check out one of the algorithms
here.
The second Stack is the real stuff that does the computation.

As i have mentioned previously, the whole expression is read by your program. One by one, the digits are stored into the Stack. However whenever an operator ( be it +, -, *, or / in the expression) is encountered, the program will pop the last two values out and evaluate them and then push the result back into the stack. Likewise, the program will complete all the operators and pop out the last value in the Stack as final result.
Here comes to the end of Part II. I hope that my guide comes in handy to you. :)
Posted by Zack at 8:19 PM
Monday, September 24, 2007
Calculator How-To Using Java 2 Part 1
Ok. Here is a little guide for those who wanna make a calculator using java 2 for whatever reasons. My guide is broken up as steps. Each step is crucial, please follow them carefully.
1. First draft out your gui layout.
Illustrated Layout below
Note: Of course you can always come out with our own fancy design.
In the above layout, you have the basic digit buttons and the 4 operator buttons( + - X* / ).
And yeah, never forget your decimal operator and your = operator. These are few neccessary buttons that you will need to make any kind of calculators.
2. Using Eclipse's Visual Editor to create your layout.
If you do not have Eclipse, download the latest version here.
Note: If you have no clue of how to use the Visual Editor. A tutorial can be found here.
It is always good to google it around to find what you need.
3. Get your buttons working.
In order for your buttons to be functional, You will need Action Listener.
A simple tutorial on this topic can be found here.
4. How a real calculator works (Implementation of Stack)
Illustration below

This is how a calculator works. When a digit button is pressed on the calculator, the value of the button goes into the stack. For operation 5 + 2, the value will enter the stack first then follow by 2. When the + operation is encountered, the 2 values ( 5 and 2 ) will be popped out from the stack. The result of 5 + 2 is then computed and pushed back into the stack.
I shall end my little guide here. The 4 steps might be short, but it can be quite a lot for you to digest. Just take your time to understand.
I will release the source code in the next coming guide.
Posted by Zack at 10:45 PM
Holiday TimeTable
YAwn! What have i been doing so far? Erm... Guess nothing fruitful... HO~ Playing game, watching tv, watching movie? What else? Crapping online... Reading books? bits here and there! Duhz... OMG that's so unproductive of me ><
Posted by Zack at 12:58 AM
Monday, September 03, 2007
Java Certification
It has been a unbearable day for me. I went for the Java certification program preperation course in school. One word to describe the course, and that is 'BORING'~ Can't believe i could sit there and listen for such long hours. Let me recall... well... 6 hours in total? Zomg. And today is only the starting of that 5 days course. 4 more days of torment... GOD BLESS ME!!! ><
Posted by Zack at 9:44 PM
Mini Game Update

i have finally completed the prototype design of my aircraft for my next mini game project.
Currently, it's just a rough layout of how the plane will look like. It will definitely going through a lot of polishing and refining, before i will model it into a real 3d model.
Posted by Zack at 9:37 PM