A simple calculator implemented using J2ME technology

Source: Internet
Author: User
Tags integer division numeric

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.