Android项目 计算器.docx
- 文档编号:15850155
- 上传时间:2023-07-08
- 格式:DOCX
- 页数:27
- 大小:666.97KB
Android项目 计算器.docx
《Android项目 计算器.docx》由会员分享,可在线阅读,更多相关《Android项目 计算器.docx(27页珍藏版)》请在冰点文库上搜索。
Android项目计算器
课程设计说明书
题目:
移动版计算器
学生姓名:
学院:
信息工程学院
班级:
计12-1班
指导教师:
庄旭菲
2015年7月
摘要:
Android是当今最重要的手机开发的平台之一,它是建立在Java基础上的,能够迅速建立手机软件的解决方案。
Android的功能十分强大。
成为当今软件行业的一股新兴力量。
Android基于Linux平台,由操作系统、用户界面和应用软件组成,具有以下特点:
开放性、应用程序无界限、应用程序是在平等条件下创建的、应用程序可以轻松的嵌入网络、应用程序可以并行运行。
第一章总体功能介绍
1.1功能介绍
计算器软件的系统功能介绍:
(1)实现简单的要实现基本的加、减、乘、除四则运算。
(2)可以实现在前一步计算结果上继续作加、减、乘、除,即连加、减、乘、除。
(3)有清空功能,即清除所有数据,重新开始计算。
(4)拥有后退按键,可以实现清除单个错误数据。
(5)可以实现复合运算。
1.2软件设计
1.2.1系统软件的结构图
1.2.2功能的操作流程
首先用户根据自己的实际需要选择计算,得出程序结果,输入数据,选择运算符号,再输入数据,选择等号,即可以得出结果。
1.2.3计算器模块
图1-1MyOntouchListener类图
图1-2Utils类图
图1-3MainActivity类图
程序中的类图如图1-1,1-2,1-3所示。
Utils中主要包含了两个方法。
分别是逆波兰式的生成以及计算结果的输出。
这两个方法为utiNi()以及calculate()
图1-1中的类是MainActivity中的子类
MainActivity中包含了按钮的点击事件以及触摸设置背景颜色,按钮字体颜色等功能。
第二章各功能模块的具体实现
2.1系统主界面
本界面是用来线性布局与网格布局,控件有文本框与按钮
android=" xmlns: tools=" android: layout_width="match_parent" android: layout_height="match_parent" android: background="#ccd0d1" android: orientation="vertical" android: paddingBottom="@dimen/activity_vertical_margin" android: paddingLeft="@dimen/activity_horizontal_margin" android: paddingRight="@dimen/activity_horizontal_margin" android: paddingTop="@dimen/activity_vertical_margin"> android: layout_width="match_parent" android: layout_height="116dp" android: background="#ccd0d1" android: orientation="vertical"> android: id="@+id/et_number" android: layout_width="match_parent" android: layout_height="58dp" android: 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: singleLine="true" android: textSize="20sp" /> android: id="@+id/et_number1" android: layout_marginTop="0dp" android: layout_width="match_parent" android: layout_height="58dp" android: layout_weight="1" android: textColor="@android: 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: textSize="40sp" /> 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="left|top" android: layout_weight="1" android: checked="false" android: textOff="" android: textOn="" /> android: layout_width="match_parent" android: layout_height="wrap_content" android: layout_weight="5" android: background="#ccd0d1" android: columnCount="5" android: orientation="horizontal" android: rowCount="6"> 2.2基本加减乘除界面 用户在文本框中输入参加运算的数据,并且点击要进行的运算符号,点击等号之后,会显示出计算结果。 点击清除按钮,可以将文本框的内容以及显示的结果一起清空,用户可以输入新的数据按钮计算。 复合运算中的表达式先生成中缀表达式,然后转换为逆波兰式。 求逆波兰式的流程图如下: 图1-4逆波兰式生成的流程图 代码实现: publicstaticStringutiNi(Stringstr) { booleanb=Pattern.matches("(\\(|[^*/.]).+(\\)|[^-+*/.])",str); if(b) { StringsrcStr=str; StringdesStr=""; booleanerrorFlag=true,isIncreaceFlag=false; charstack[]=newchar[100]; intpostion=0,top=0; while(postion<=srcStr.length()-1) { chartemch=srcStr.charAt(postion); if(temch=='(') { top++; stack[top]=temch; isIncreaceFlag=false; }elseif(temch==')') { while(stack[top]! ='(') { if(top==0) { errorFlag=false; break; }else { desStr+=','; desStr+=stack[top]; top--; } } top--; isIncreaceFlag=false; }elseif(temch=='+'||temch=='-') { while(top! =0&&stack[top]! ='(') { desStr+=','; desStr+=stack[top]; top--; } if(postion==0) { desStr+=temch; } elseif(postion==1&&str.charAt(0)=='(') { desStr+=temch; } else { top++; stack[top]=temch; } isIncreaceFlag=false; } elseif(temch=='*'||temch=='/') { while(stack[top]=='*'||stack[top]=='/') { desStr+=','; desStr+=stack[top]; top--; } top++; stack[top]=temch; isIncreaceFlag=false; }else { if((isIncreaceFlag==false) &&postion>0 &&srcStr.charAt(postion-1)! ='(' ) { if((postion==2)&&(str.charAt(0)=='(')); elseif((postion==1)&&(str.charAt(0)=='+'||str.charAt(0)=='-')); else{ desStr+=','; } } desStr+=temch; isIncreaceFlag=true; } postion++; } while(top! =0) { if(stack[top]=='(') { errorFlag=false; break; } else { desStr+=','; desStr+=stack[top]; top--; } } if(errorFlag==true) returndesStr; } returnnull;} 2.3其他运算界面 可以实现的是切换界面风格。 括号的实现以及清除和后退: elseif("√".equals(opera)){ if(firstNumber.equals("")){ ed_out.setText("根号内不Null"); firstNumber=""; SecondNumber=""; numberString="";
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- Android项目 计算器 Android 项目