In the actual learning process, often do some small projects, you can learn the technology integrated application, get a certain sense of achievement, and exercise logical thinking ability.
Functions of this calculator code:
1, implementation of arithmetic, where division is to achieve the integer division
2. Realize the input function clearly
The core idea of implementing this function:
1, the function of this program is divided into state, a total of three states:
A) Enter the first number state
b Enter the operation symbol status
c) Enter a second digit state
Through the state Division, each state for the corresponding drawing and event processing, so the logic is clearer, writing code is relatively simple.
2, the data storage
In the calculator program, the storage data is a relatively core logic, this procedure realizes the way, determines whether the user presses is the numeric key (KEY_NUM0 to KEY_NUM9), these keys keycode and the corresponding character code same, for example KEY_NUM0 and the character 0 code, Using this rule, the value of the numeric keypad can be obtained by KEYCODE–KEY_NUM0.
This translates only one input at a time, and the actual input result should be equal to:
The last value entered x10+ the contents of this entry
For example, the last entered is 1, this time enter 3, the actual input should be 1x10 + 3 = 13
This program stores user input in such a way.
Operation instructions of this procedure:
1, digital input by the number key to achieve
2, the operation symbol uses the asterisk key to enter, presses the star key to switch once the operation symbol
3, left soft key on behalf of the purge, each clear a number or operator
4, right Soft key code calculation, calculate the actual results