Android項(xiàng)目計(jì)算器DOC_第1頁(yè)
Android項(xiàng)目計(jì)算器DOC_第2頁(yè)
Android項(xiàng)目計(jì)算器DOC_第3頁(yè)
Android項(xiàng)目計(jì)算器DOC_第4頁(yè)
Android項(xiàng)目計(jì)算器DOC_第5頁(yè)
已閱讀5頁(yè),還剩19頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

1、學(xué)校代碼: 10128學(xué) 號(hào): 課程設(shè)計(jì)說(shuō)明書題 目: 移動(dòng)版計(jì)算器學(xué)生姓名: 學(xué) 院: 信息工程學(xué)院班 級(jí): 計(jì)12-1班指導(dǎo)教師: 莊旭菲 2015 年 7 月 目錄第一章 總體功能介紹11.1功能介紹11.2軟件設(shè)計(jì)11.2.1系統(tǒng)軟件的結(jié)構(gòu)圖11.2.2功能的操作流程11.2.3計(jì)算器模塊1第二章 各功能模塊的具體實(shí)現(xiàn)32.1系統(tǒng)主界面32.2基本加減乘除界面92.3其他運(yùn)算界面12第三章 調(diào)試及運(yùn)算結(jié)果163.1加法運(yùn)算結(jié)果163.2減法運(yùn)算結(jié)果163.3乘法運(yùn)算結(jié)果173.4除法運(yùn)算結(jié)果173.5帶括號(hào)運(yùn)算結(jié)果173.6復(fù)合運(yùn)算結(jié)果17第四章 總結(jié)18 摘要:Android是當(dāng)今最

2、重要的手機(jī)開發(fā)的平臺(tái)之一,它是建立在Java基礎(chǔ)上的,能夠迅速建立手機(jī)軟件的解決方案。Android的功能十分強(qiáng)大。成為當(dāng)今軟件行業(yè)的一股新興力量。Android基于Linux平臺(tái),由操作系統(tǒng)、用戶界面和應(yīng)用軟件組成,具有以下特點(diǎn):開放性、應(yīng)用程序無(wú)界限、應(yīng)用程序是在平等條件下創(chuàng)建的、應(yīng)用程序可以輕松的嵌入網(wǎng)絡(luò)、應(yīng)用程序可以并行運(yùn)行。 第一章 總體功能介紹1.1功能介紹計(jì)算器軟件的系統(tǒng)功能介紹:(1) 實(shí)現(xiàn)簡(jiǎn)單的要實(shí)現(xiàn)基本的加、減、乘、除四則運(yùn)算。 (2) 可以實(shí)現(xiàn)在前一步計(jì)算結(jié)果上繼續(xù)作加、減、乘、除,即連加、減、乘、 除。(3) 有清空功能,即清除所有數(shù)據(jù),重新開始計(jì)算。(4) 擁有后退按

3、鍵,可以實(shí)現(xiàn)清除單個(gè)錯(cuò)誤數(shù)據(jù)。(5) 可以實(shí)現(xiàn)復(fù)合運(yùn)算。1.2軟件設(shè)計(jì)1.2.1系統(tǒng)軟件的結(jié)構(gòu)圖1.2.2功能的操作流程 首先用戶根據(jù)自己的實(shí)際需要選擇計(jì)算,得出程序結(jié)果,輸入數(shù)據(jù),選擇運(yùn)算符號(hào),再輸入數(shù)據(jù),選擇等號(hào),即可以得出結(jié)果。1.2.3計(jì)算器模塊圖1-1 MyOntouchListener 類圖圖1-2 Utils類圖圖1-3 MainActivity類圖程序中的類圖如圖1-1,1-2,1-3所示。Utils中主要包含了兩個(gè)方法。分別是逆波蘭式的生成以及計(jì)算結(jié)果的輸出。這兩個(gè)方法為utiNi()以及calculate()圖1-1中的類是MainActivity中的子類MainActiv

4、ity中包含了按鈕的點(diǎn)擊事件以及觸摸設(shè)置背景顏色,按鈕字體顏色等功能。第二章 各功能模塊的具體實(shí)現(xiàn)2.1系統(tǒng)主界面 本界面是用來(lái)線性布局與網(wǎng)格布局,控件有文本框與按鈕 <LinearLayout xmlns:android=" xmlns:tools=" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#ccd0d1" android:orientation="v

5、ertical" android:paddingBottom="dimen/activity_vertical_margin" android:paddingLeft="dimen/activity_horizontal_margin" android:paddingRight="dimen/activity_horizontal_margin" android:paddingTop="dimen/activity_vertical_margin" ><LinearLayout android

6、:layout_width="match_parent" android:layout_height="116dp" android:background="#ccd0d1" android:orientation="vertical" > <EditText android:id="+id/et_number" android:layout_width="match_parent" android:layout_height="58dp"an

7、droid:layout_weight="1"android:textColor="android:color/black" android:background="drawable/et_bg1_01" android:gravity="right|bottom" android:paddingRight="10dp" android:paddingBottom="5dp" android:focusable="false" android:single

8、Line="true" android:textSize="20sp" /> <EditText android:id="+id/et_number1" android:layout_marginTop="0dp" android:layout_width="match_parent" android:layout_height="58dp"android:layout_weight="1"android:textColor="and

9、roid:color/black" android:background="drawable/et_bg1_02" android:gravity="right|bottom" android:paddingRight="10dp" android:paddingBottom="5dp" android:hint="0" android:focusable="false"android:singleLine="true" android:text

10、Size="40sp" /> </LinearLayout> <Switch android:id="+id/switchButton" android:layout_width="wrap_content" android:layout_height="wrap_content" android:thumb="drawable/thumb" android:track="drawable/track" android:layout_gravity=&

11、quot;left|top" android:layout_weight="1" android:checked="false" android:textOff="" android:textOn="" /> <GridLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="5" and

12、roid:background="#ccd0d1" android:columnCount="5" android:orientation="horizontal" android:rowCount="6" > <Button android:id="+id/bt_left" android:layout_width="60dp" android:layout_height="48dp" android:textColor="#616

13、A73" android:background="drawable/bg_bt2" android:layout_row="1" android:text="(" /> <Button android:id="+id/bt_right" android:layout_width="60dp" android:layout_height="48dp" android:textColor="#616A73" android:backgro

14、und="drawable/bg_bt2" android:text=")" /> <Button android:id="+id/bt_C" android:layout_width="60dp" android:layout_height="48dp" android:textColor="#F07E21" android:background="drawable/bg_bt2" android:text="C" /&g

15、t; <Button android:id="+id/bt_DEL" android:layout_width="60dp" android:layout_height="48dp" android:textColor="#616A73" android:background="drawable/bg_bt2" android:layout_columnSpan="2" android:layout_gravity="fill_horizontal"

16、 android:text="DEL" /> <Button android:id="+id/bt_7" android:layout_width="60dp" android:layout_height="48dp" android:textColor="#616A73" android:background="drawable/bg_bt1" android:text="7" /> <Button android:id=&quo

17、t;+id/bt_8" android:layout_width="60dp" android:layout_height="48dp" android:textColor="#616A73" android:background="drawable/bg_bt1" android:text="8" /> <Button android:id="+id/bt_9" android:layout_width="60dp" android

18、:layout_height="48dp" android:textColor="#616A73" android:background="drawable/bg_bt1" android:text="9" /> <Button android:id="+id/bt_cf" android:layout_width="60dp" android:layout_height="48dp" android:textColor="#616A

19、73" android:background="drawable/bg_bt2" android:layout_columnSpan="2" android:layout_gravity="fill_horizontal" android:text="/" /> <Button android:id="+id/bt_4" android:layout_width="60dp" android:layout_height="48dp"

20、android:textColor="#616A73" android:background="drawable/bg_bt1" android:layout_row="5" android:text="4" /> <Button android:id="+id/bt_5" android:layout_width="60dp" android:layout_height="48dp" android:textColor="#616A

21、73" android:background="drawable/bg_bt1" android:text="5" /> <Button android:id="+id/bt_6" android:layout_width="60dp" android:layout_height="48dp" android:textColor="#616A73" android:background="drawable/bg_bt1" androi

22、d:text="6" /> <Button android:id="+id/bt_mul" android:layout_width="60dp" android:layout_height="48dp" android:textColor="#616A73" android:background="drawable/bg_bt2" android:layout_columnSpan="2" android:layout_gravity=&qu

23、ot;fill_horizontal" android:text="*" /> <Button android:id="+id/bt_1" android:layout_width="60dp" android:layout_height="48dp" android:textColor="#616A73" android:background="drawable/bg_bt1" android:text="1" /> <

24、Button android:id="+id/bt_2" android:layout_width="60dp" android:layout_height="48dp" android:textColor="#616A73" android:background="drawable/bg_bt1" android:text="2" /> <Button android:id="+id/bt_3" android:layout_width=&q

25、uot;60dp" android:layout_height="48dp" android:textColor="#616A73" android:background="drawable/bg_bt1" android:text="3" /> <Button android:id="+id/bt_jf" android:layout_width="60dp" android:layout_height="48dp" android

26、:textColor="#616A73" android:background="drawable/bg_bt2" android:layout_columnSpan="2" android:layout_gravity="fill_horizontal" android:text="-" /> <Button android:id="+id/bt_0" android:layout_width="60dp" android:layout_he

27、ight="48dp" android:textColor="#616A73" android:background="drawable/bg_bt1" android:layout_columnSpan="2" android:layout_gravity="fill_horizontal" android:text="0" /> <Button android:id="+id/bt_point" android:layout_width=&

28、quot;60dp" android:layout_height="48dp" android:textColor="#616A73" android:background="drawable/bg_bt1" android:text="." /> <Button android:id="+id/bt_add" android:layout_width="60dp" android:layout_height="48dp" andro

29、id:textColor="#616A73" android:background="drawable/bg_bt2" android:layout_columnSpan="2" android:layout_gravity="fill" android:layout_rowSpan="2" android:text="+" /> <Button android:id="+id/bt_sum" android:layout_width=&quo

30、t;60dp" android:layout_height="48dp" android:textColor="#FFFDFD" android:background="drawable/ic_launcher" android:layout_columnSpan="3" android:layout_gravity="fill" android:text="=" /> </GridLayout></LinearLayout>2.2基本

31、加減乘除界面用戶在文本框中輸入?yún)⒓舆\(yùn)算的數(shù)據(jù),并且點(diǎn)擊要進(jìn)行的運(yùn)算符號(hào),點(diǎn)擊等號(hào)之后,會(huì)顯示出計(jì)算結(jié)果。點(diǎn)擊清除按鈕,可以將文本框的內(nèi)容以及顯示的結(jié)果一起清空,用戶可以輸入新的數(shù)據(jù)按鈕計(jì)算。復(fù)合運(yùn)算中的表達(dá)式先生成中綴表達(dá)式,然后轉(zhuǎn)換為逆波蘭式。求逆波蘭式的流程圖如下:圖1-4 逆波蘭式生成的流程圖代碼實(shí)現(xiàn):public static String utiNi(String str)boolean b = Pattern.matches("(|*/.).+()|-+*/.)", str);if (b)String srcStr = str;String desStr = &

32、quot;"boolean errorFlag = true, isIncreaceFlag = false;char stack = new char100;int postion = 0, top = 0;while (postion <= srcStr.length() - 1)char temch = srcStr.charAt(postion);if (temch = '(')top+;stacktop = temch;isIncreaceFlag = false; else if (temch = ')')while (stackto

33、p != '(')if (top = 0)errorFlag = false;break; elsedesStr += ','desStr += stacktop;top-;top-;isIncreaceFlag = false; else if (temch = '+' | temch = '-')while (top != 0 && stacktop != '(')desStr += ','desStr += stacktop;top-;if (postion = 0)desSt

34、r += temch;else if(postion = 1&&str.charAt(0)='(')desStr += temch;elsetop+;stacktop = temch;isIncreaceFlag = false;else if (temch = '*' | temch = '/')while (stacktop = '*' | stacktop = '/')desStr += ','desStr += stacktop;top-;top+;stacktop = te

35、mch;isIncreaceFlag = false; elseif (isIncreaceFlag = false)&& postion > 0&& srcStr.charAt(postion - 1) != '(')if(postion=2)&&(str.charAt(0)='(');else if(postion=1)&&(str.charAt(0)='+'|str.charAt(0)='-');else desStr += ','desS

36、tr += temch;isIncreaceFlag = true;postion+;while (top != 0)if (stacktop = '(')errorFlag = false;break;elsedesStr += ','desStr += stacktop;top-;if (errorFlag = true)return desStr;return null;2.3其他運(yùn)算界面可以實(shí)現(xiàn)的是切換界面風(fēng)格。括號(hào)的實(shí)現(xiàn)以及清除和后退: else if ("".equals(opera) if (firstNumber.equals

37、("") ed_out.setText("根號(hào)內(nèi)不Null");firstNumber = ""SecondNumber = ""numberString = ""text = ""ed_in.setText(""); else result = Math.sqrt(Double.parseDouble(firstNumber);ed_out.setText(" " + firstNumber + " = "+ St

38、ring.valueOf(result);ed_in.setText(""); else if ("".equals(opera) if (firstNumber.equals("") ed_out.setText("底數(shù)不Null");firstNumber = ""SecondNumber = ""numberString = ""text = ""ed_in.setText(""); else if (Seco

39、ndNumber.equals("") ed_out.setText("指數(shù)不Null");firstNumber = ""SecondNumber = ""numberString = ""text = ""ed_in.setText(""); else result = exponentFun(Double.parseDouble(firstNumber),Double.parseDouble(SecondNumber);ed_out.setText(

40、firstNumber + " "+ SecondNumber + " = "+ String.valueOf(result);ed_in.setText(""); else if ("".equals(opera) if (firstNumber.equals("") firstNumber = ""SecondNumber = ""numberString = ""text = ""ed_in.setText(&

41、quot;"); else result = factorialFun(Double.parseDouble(firstNumber); else if ("".equals(text) opera = ""firstNumber = numberString;numberString = ""ed_in.setText(numberString);ed_out.setText(" " + firstNumber); else if ("".equals(text) opera = &

42、quot;"firstNumber = numberString;numberString = ""ed_in.setText(numberString);ed_out.setText(firstNumber + " "); else if ("".equals(text) opera = ""firstNumber = numberString;numberString = ""ed_in.setText(numberString);ed_out.setText(firstNumbe

43、r + " ");sound(); else if ("c".equals(text) opera = ""firstNumber = ""SecondNumber = ""numberString = ""text = ""ed_in.setText("");ed_out.setText(""); else if ("".equals(text) if (!numberString.equals("") numberString = String.copyValueOf(numberString.toCharArray(), 0,numberString.length() - 1);ed_in.setText(numberString); else if ("".equals(text) numberString = numberString;ed_in.setText(numberString); else numberString = numberStrin

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

最新文檔

評(píng)論

0/150

提交評(píng)論