版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)
文檔簡介
1、Java源代碼package com.example.jisuanqi;import java.util.Date;import android.app.Activity;import android.os.Bundle;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;import android.widget.EditText;public class MainActivity extends Activity private Button one;p
2、rivate Button two;private Button three;private Button four;private Button five;private Button six;private Button seven;private Button eight;private Button nine;private Button zero;private Button dot;private Button add;private Button sub;private Button mult;private Button division;private Button amou
3、nt;private Button clear;private Button time;private Button sqrt;private Button pow;private EditText led;String num1 = ;String num2 = ;double num3 = 0;String rezult = ;String sign = null;int mark = 0;boolean flag = true;boolean dotmark = true;protected void onCreate(Bundle savedInstanceState) super.o
4、nCreate(savedInstanceState);setContentView(R.layout.activity_main);zero = (Button) findViewById(R.id.zero);one = (Button) findViewById(R.id.one);two = (Button) findViewById(R.id.two);three = (Button) findViewById(R.id.three);four = (Button) findViewById(R.id.four);five = (Button) findViewById(R.id.f
5、ive);six = (Button) findViewById(R.id.six);seven = (Button) findViewById(R.id.seven);eight = (Button) findViewById(R.id.eight);nine = (Button) findViewById(R.id.nine);dot = (Button) findViewById(R.id.dot);add = (Button) findViewById(R.id.add);sub = (Button) findViewById(R.id.sub);mult = (Button) fin
6、dViewById(R.id.mult);division = (Button) findViewById(R.id.division);clear = (Button) findViewById(R.id.clear);amount = (Button) findViewById(R.id.amount);time = (Button) findViewById(R.id.time);pow = (Button) findViewById(R.id.pow);sqrt = (Button) findViewById(R.id.sqrt);led = (EditText) findViewBy
7、Id(R.id.led);zero.setOnClickListener(new OnClickListener() public void onClick(View v) if (mark = 0) num1 = num1 + 0;led.setText(num1); else if (mark = 1) num2 = num2 + 0;led.setText(num1 + sign + num2); else num1 = String.valueOf(num3);num2 = num2 + 0;led.setText(num1 + sign + num2););one.setOnClic
8、kListener(new OnClickListener() public void onClick(View v) if (mark = 0) num1 = num1 + 1;led.setText(num1); else if (mark = 1) num2 = num2 + 1;led.setText(num1 + sign + num2); else num1 = String.valueOf(num3);num2 = num2 + 1;led.setText(num1 + sign + num2););two.setOnClickListener(new OnClickListen
9、er() public void onClick(View v) if (mark = 0) num1 = num1 + 2;led.setText(num1); else if (mark = 1) num2 = num2 + 2;led.setText(num1 + sign + num2); else num1 = String.valueOf(num3);num2 = num2 + 2;led.setText(num1 + sign + num2););three.setOnClickListener(new OnClickListener() public void onClick(
10、View v) if (mark = 0) num1 = num1 + 3;led.setText(num1); else if (mark = 1) num2 = num2 + 3;led.setText(num1 + sign + num2); else num1 = String.valueOf(num3);num2 = num2 + 3;led.setText(num1 + sign + num2););four.setOnClickListener(new OnClickListener() public void onClick(View v) if (mark = 0) num1
11、 = num1 + 4;led.setText(num1); else if (mark = 1) num2 = num2 + 4;led.setText(num1 + sign + num2); else num1 = String.valueOf(num3);num2 = num2 + 4;led.setText(num1 + sign + num2););five.setOnClickListener(new OnClickListener() public void onClick(View v) if (mark = 0) num1 = num1 + 5;led.setText(nu
12、m1); else if (mark = 1) num2 = num2 + 5;led.setText(num1 + sign + num2); else num1 = String.valueOf(num3);num2 = num2 + 5;led.setText(num1 + sign + num2););six.setOnClickListener(new OnClickListener() public void onClick(View v) if (mark = 0) num1 = num1 + 6;led.setText(num1); else if (mark = 1) num
13、2 = num2 + 6;led.setText(num1 + sign + num2); else num1 = String.valueOf(num3);num2 = num2 + 6;led.setText(num1 + sign + num2););seven.setOnClickListener(new OnClickListener() public void onClick(View v) if (mark = 0) num1 = num1 + 7;led.setText(num1); else if (mark = 1) num2 = num2 + 7;led.setText(
14、num1 + sign + num2); else num1 = String.valueOf(num3);num2 = num2 + 7;led.setText(num1 + sign + num2););eight.setOnClickListener(new OnClickListener() public void onClick(View v) if (mark = 0) num1 = num1 + 8;led.setText(num1); else if (mark = 1) num2 = num2 + 8;led.setText(num1 + sign + num2); else
15、 num1 = String.valueOf(num3);num2 = num2 + 8;led.setText(num1 + sign + num2););nine.setOnClickListener(new OnClickListener() public void onClick(View v) if (mark = 0) num1 = num1 + 9;led.setText(num1); else if (mark = 1) num2 = num2 + 9;led.setText(num1 + sign + num2); else num1 = String.valueOf(num
16、3);num2 = num2 + 9;led.setText(num1 + sign + num2););add.setOnClickListener(new OnClickListener() public void onClick(View v) if (flag) sign = +;mark+;flag = false;dotmark = true;);sub.setOnClickListener(new OnClickListener() public void onClick(View v) if (flag) sign = -;mark+;flag = false;dotmark
17、= true;);mult.setOnClickListener(new OnClickListener() public void onClick(View v) if (flag) sign = *;mark+;flag = false;dotmark = true;);division.setOnClickListener(new OnClickListener() public void onClick(View v) if (flag) sign = ;mark+;flag = false;dotmark = true;);pow.setOnClickListener(new OnC
18、lickListener() public void onClick(View v) if (flag) sign = ;mark+;flag = false;dotmark = true;);dot.setOnClickListener(new OnClickListener() public void onClick(View v) if (dotmark) if (mark = 0) num1 = num1 + .;led.setText(num1); else if (mark = 1) num2 = num2 + .;led.setText(num1 + sign + num2);
19、else num1 = String.valueOf(num3);num2 = num2 + .;led.setText(num1 + sign + num2);dotmark = false;);amount.setOnClickListener(new OnClickListener() / 等于時發(fā)生的運算public void onClick(View v) flag = true;dotmark = true;if (sign.equals(+) double x = Double.parseDouble(num1);double y = Double.parseDouble(num
20、2);num3 = x + y;rezult = String.valueOf(num3);led.setText(num1 + sign + num2 + = + rezult);num2 = ; else if (sign.equals(-) double x = Double.parseDouble(num1);double y = Double.parseDouble(num2);num3 = x - y;rezult = String.valueOf(num3);led.setText(num1 + sign + num2 + = + rezult);num2 = ; else if
21、 (sign.equals(*) double x = Double.parseDouble(num1);double y = Double.parseDouble(num2);num3 = x * y;rezult = String.valueOf(num3);led.setText(num1 + sign + num2 + = + rezult);num2 = ; else if (sign.equals() double x = Double.parseDouble(num1);double y = Double.parseDouble(num2);num3 = x / y;rezult = String.valueOf(num3);led.setText(num1 + sign + num2 + = + rezult);num2 = ; else if (sign.equals() double x = Double.parseD
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 四年級數(shù)學(xué)(四則混合運算帶括號)計算題專項練習(xí)與答案
- 五年級數(shù)學(xué)(小數(shù)乘法)計算題專項練習(xí)及答案
- 教育心理學(xué)在少兒教育實踐中的運用
- 四年級數(shù)學(xué)(小數(shù)加減運算)計算題專項練習(xí)與答案
- 二零二五年度城市綜合管廊建設(shè)項目建議書編制協(xié)議3篇
- 二零二五年度旅游文化體驗項目合作合同范本4篇
- 現(xiàn)代家庭中的心理健康管理策略
- 2025年人教版(2024)高三化學(xué)上冊月考試卷含答案
- 廣告位租賃合同模板
- 2025年北師大版八年級科學(xué)上冊月考試卷含答案
- 大數(shù)據(jù)管理與考核制度大全
- 大學(xué)面試后感謝信
- 2022屆上海高考語文調(diào)研試測卷詳解(有《畏齋記》“《江表傳》曰…”譯文)
- SBT11229-2021互聯(lián)網(wǎng)舊貨交易平臺建設(shè)和管理規(guī)范
- 如何打造頂尖理財顧問團(tuán)隊
- 土壤農(nóng)化分析課件
- 小區(qū)大型團(tuán)購活動策劃
- NEC(新生兒壞死性小腸結(jié)腸炎)92273
- 2023年租賃風(fēng)控主管年度總結(jié)及下一年展望
- 開關(guān)插座必看的七個安全隱患范文
- 高分子成型加工課件
評論
0/150
提交評論