基于安卓的计算器的设计与实现

合集下载

基于Android的计算器

基于Android的计算器

基于Android的计算器引言计算器是人们日常生活中常用的工具之一。

随着智能手机的广泛应用,计算器应用也成为了手机中的一个必备工具。

本文将介绍基于Android平台开发的计算器应用。

功能特点1.基本四则运算:加减乘除2.小数点输入和计算3.括号嵌套运算4.撤销和重做操作5.运算结果精确显示技术实现开发环境•Android Studio:用于开发Android应用的集成开发环境•Java语言:用于编写Android应用程序的主要语言用户界面设计计算器应用的用户界面需要具备简洁、直观的特点,方便用户进行操作。

基于Android平台的计算器通常使用网格布局来展示数字和功能按钮。

每个按钮都会响应用户的点击事件。

数据处理计算器应用的核心功能是进行数学运算。

因此,需要通过算法来处理用户输入的数学表达式。

一般情况下,可以使用栈数据结构来解决这个问题。

通过将中缀表达式转换为后缀表达式,然后再通过后缀表达式进行计算,即可得到最终的结果。

界面交互计算器应用需要监听用户的输入操作,并根据用户的操作更新界面。

例如,当用户点击了数字按钮或者符号按钮时,计算器应该能够正确地处理用户的输入,并实时更新显示的表达式和结果。

数据精确性为了保证计算结果的精确性,可以使用BigDecimal类来进行数值运算。

BigDecimal类可以处理浮点数运算时的精度问题,并提供了大数运算的功能。

开发过程创建Android计算器项目首先在Android Studio中创建一个新的Android项目。

选择适当的项目名称、包名和最低支持的Android版本。

设计用户界面布局使用XML布局文件来设计计算器应用的用户界面。

使用网格布局来创建数字和操作按钮,并设置按钮的点击事件监听。

添加按钮点击事件在Java代码中,为计算器界面上的按钮添加点击事件监听器。

根据用户的点击事件,对用户输入的数学表达式进行处理,并更新界面的显示。

数学表达式处理通过算法处理用户输入的表达式。

Android平台上的计算器设计

Android平台上的计算器设计

武汉工程大学计算机科学与工程学院综合设计报告设计名称:信息系统综合设计设计题目:Android平台上的计算器设计学生学号:专业班级:学生姓名:学生成绩:指导教师(职称):吴静(讲师)课题工作时间:2012年3月19日至2012年5月25日说明:1、报告中的第一、二、三项由指导教师在综合设计开始前填写并发给每个学生;四、五两项(中英文摘要)由学生在完成综合设计后填写。

2、学生成绩由指导教师根据学生的设计情况给出各项分值及总评成绩。

3、指导教师评语一栏由指导教师就学生在整个设计期间的平时表现、设计完成情况、报告的质量及答辩情况,给出客观、全面的评价。

4、所有学生必须参加综合设计的答辩环节,凡不参加答辩者,其成绩一律按不及格处理。

答辩小组成员应由2人及以上教师组成。

5、报告正文字数一般应不少于5000字,也可由指导教师根据本门综合设计的情况另行规定。

6、平时表现成绩低于6分的学生,其综合设计成绩按不及格处理。

7、此表格式为武汉工程大学计算机科学与工程学院提供的基本格式(适用于学院各类综合设计),各教研室可根据本门综合设计的特点及内容做适当的调整,并上报学院批准。

成绩评定表学生姓名:学号:班级:答辩记录表指导教师评语目录摘要........................................................................................................................................................ - 1 -ABSTRACT ............................................................................................................................................... - 2 -第一章引言.............................................................................................................................................. - 3 -1.1课题背景及意义 (3)1.1.1课题背景................................................................................................................................ - 3 -1.1.2课题相关的技术知识.............................................................................................................. - 4 -1.2智能手机平台系统 (7)1.3课题来源 (8)第二章系统分析...................................................................................................................................... - 9 -2.1系统可行性分析 (9)2.2系统的开发语言的选择 (9)2.3系统的开发工具简介 (9)2.3.1 JDK .......................................................................................................................................... - 9 -2.3.2 WTK ....................................................................................................................................... - 10 -2.3.3 Eclipse .................................................................................................................................... - 10 -2.3.4 EclipseMe ................................................................................................................................- 11 -第三章基于ANDROID平台计算器相关技术概述............................................................................ - 12 -3.1A NDROID手机平台 (12)3.1.1Android起源及优势 .............................................................................................................. - 12 -3.1.2Android体系结构 .................................................................................................................. - 12 -3.1.3Android平台功能特征 .......................................................................................................... - 14 -3.2A NDROID SDK介绍 (15)3.3XML技术 (16)3.4JNI技术 (16)第四章基于ANDROID平台计算器设计............................................................................................ - 18 -4.1系统的总体设计 (18)4.2程序流程和系统功能设计 (18)4.2.1 程序流程设计....................................................................................................................... - 18 -4.2.2 系统功能设计....................................................................................................................... - 19 -4.3基于A NDROID平台系统具体设计 (20)4.3.1 总体模块详细设计............................................................................................................... - 20 -4.3.2 输入模块详细设计............................................................................................................... - 20 -4.3.3 显示模块详细设计............................................................................................................... - 21 -4.3.4 计算模块详细设计............................................................................................................... - 21 -第五章计算器系统实现........................................................................................................................ - 23 -5.1A NDROID应用程序构成 (23)5.2A NDROID应用系统文件结构 (23)5.3构建A NDROID应用程序用户界面 (25)5.3.1 Android应用程序界面组件.................................................................................................. - 25 -5.3.2 Android应用系统界面组件.................................................................................................. - 26 -5.3.3 Android用户界面的实现...................................................................................................... - 27 -5.4计算模块的实现 (30)武汉工程大学计算机科学与工程学院综合设计报告5.5计算器演示 (33)总结...................................................................................................................................................... - 35 -致谢...................................................................................................................................................... - 36 -参考文献.................................................................................................................................................. - 37 -附录.......................................................................................................................................................... - 38 -摘要目前手机可以说是普及率非常高的电子设备了,由于其便于携带,使用方便,资费适中等等原因,现在手机已经在一定程度开始代替固定电话的通话功能,以及一些原来电脑软件上的功能了。

基于Android计算器功能的实现毕业设计

基于Android计算器功能的实现毕业设计

基于Android计算器功能的实现摘要随着移动通信技术和网络技术的迅速发展,手机系统发生了巨大的变化,从进行简单通话功能的非智能手机到现在集上网、聊天、收发邮件、视屏电话会议等各种服务于娱乐为一身的智能手机系统。

由Google公司牵头众多实力雄厚的软硬件厂商加盟成立了OMS联盟,并推出的Android平台手机系统。

作为时代的新生儿,Android手机操作平台有着得天独厚的优势广阔的发展前景。

本文正是基于Android平台开发的计算器。

论文主要阐述以面向对象的程序开发语言eclipse为开发工具, 设计并实现基于Android的计算器。

论文首先介绍了Android开发平台和环境以及Android 工程的重要部分,其次对计算器系统和程序进行了分析和设计,再次对计算器进行了系统的实现,并对系统进行了严格的验证,最后本文对所做工作进行了总结。

关键词:手机,Android,用户界面,计算器THE CALCULATOR FUNCTION REALIZATION BASEDON ANDROIDABSTRACTWith the development of mobile communication technology and network technology, great changes have taken place on the mobile phone system. The original mobile phone only has the functions of communication and Smartphone has the functions of internet, chat, video conferencing and other services and entertainment. Android mobile phone platform which was developed by Google Company and many equipment manufacturers of hardware and software vendors, as the era of neonatal has a unique advantage and prospects for development. This article is based on the Android platform calculator. The thesis describes object-oriented programming language eclipse development tools, design and implement a calculator based on the Android. The paper first introduces the Android development platform and environment as well as an important part of the Android project, followed by the calculator systems and procedures analysis and design, the realization of the system once again the calculator, and strict verification, Finally, a summary of the work done.Key words: mobile phone, Android, UI, calculator毕业设计(论文)原创性声明和使用授权说明原创性声明本人郑重承诺:所呈交的毕业设计(论文),是我个人在指导教师的指导下进行的研究工作及取得的成果。

基于Android平台的绩点计算器设计与实现

基于Android平台的绩点计算器设计与实现
一、Android概述
1.1 Android简介
Android这一词原本的意思是指“机器人”,Google公司在2008年宣布一款基于Linux平台的开源手机操作系统,这款操作系统的名字也叫Android,它是第一个为移动终端打造的真正开放、完整的移动软件,它的开放性是非常高的。[5]操作系统、中间件、用户界面和应用软件构成该操作平台。[6]现如今大多数智能手机的系统都是Android系统,而现在智能手机已经渐渐融入我们的生活的方方面面,我们越来越离不开手机,一些手机应用深入人心,因此,安卓系统已经广为人知。
二、绩点制概念及计算方法
由于学分制只能计算学习的量,导致学生只追求修满学分,而不注重学习成绩的质量,学生之间的成绩也不能进行横向比较。绩点是计算学习成绩的一种方法。[8]平均学分绩点(General Point Average,即GPA)是以学分与绩点作为衡量学生学习的量与质的计算单位,以取得一定的学分和平均学分绩点作为毕业以及获得学位的标准,实施多样化的教育规格以及较为灵活的教学管理制度。[9]绩点体现了课程学习的质量好,将该学生掌握课程知识的情况得以反映,而不包含绩点的学分制是不够完善的。[10]相应的课程成绩对应着相应的课程绩点,计算学分绩点,要将某个学生所修的全部课程(重修的课程也要包含在内)的课程成绩对应的课程绩点乘以该门课程的学分,计算学分总计,则将学分绩点累加后再除以总的课程学分。
【 关 键 词 】学分;绩点制;Android;eclipse
目录
引言 3
一、 Android概述 4
1.1 Android简介 4
1.2 Android现状 4
二、绩点制概念及计算方法 4
三、研究内容及意义 5
四、系统分析 5
五、系统设计 5

android开发——简易计算器的设计报告

android开发——简易计算器的设计报告

简易计算机的设计摘要:Android是当今最重要的手机开发平台之一,它是建立在Java基础之上的,能够迅速建立手机软件的解决方案。

Android的功能十分强大,成为当今软件行业的一股新兴力量。

Android基于Linux平台,由操作系统、中间件、用户界面和应用软件组成,具有以下5个特点:开放性、应用程序无界限、应用程序是在平等条件下创建的、应用程序可以轻松的嵌入网络、应用程序可以并行运行。

一、实训目的1、了解Android系统,学会Android开发环境的搭建。

2、了解E clipse,学会用E clipse和Java 开发一个Android程序。

3、进一步巩固课堂上所学到的知识,深刻把握Java语言的重要概念及其面向对象的特性,能够熟练的应用面向对象的思想和设计方法解决实际问题的能力。

4、巩固所学Java语言基本知识,增进Java语言编辑基本功,掌握JDK、Editplus、Eclipse、JCreator等开发工具的运用,拓宽常用类库的应用。

二、实训任务1、Activity的相关知识简单理解Activity 代表一个用户所能看到的屏幕,Activity 主要是处理一个应用的整体性工作。

Activity是最基本的Android 应用程序组件,应用程序中,一个活动通常就是一个单独的屏幕。

每一个活动都被实现为一个独立的类,并且从活动基类中继承而来,活动类将会显示由视图控件组成的用户接口,并对事件做出响应。

大多数的应用是由多个屏幕显示组成,因而要用到多个Activity。

(1)Activity的相关方法及相关函数:void onCreate(Bundle)首次启动时调用,接受参数:Null or savedInstanceState(保存的以前某些状态信息);void onStart() 说明了将要显示给用户的活动;void onRestart()将处于停止状态的活动重新显示给用户;void onResume()用户可以开始与活动进行交互时调用。

《Android编程技术》---基于Android的简易的计算器的设计与实现

《Android编程技术》---基于Android的简易的计算器的设计与实现
clear_flag=false;
etinput="";
etInput.setText("");
}
etInput.setText(etinput+((Button)v).getText());//点击数字和小数点直接显示内容
break;
caseR.id.btJia:
caseR.id.btJian:
caseR.id.btMul:
btMul.setOnClickListener(this);
btDivide.setOnClickListener(this);
btEqu.setOnClickListener(this);
btClear.setOnClickListener(this);
btDel.setOnClickListener(this);
cleБайду номын сангаасr_flag=false;
return;
}
clear_flag=true;
doubleresult=0;
String s1=exp.substring(0,exp.indexOf(" "));//运算符前面的字符串
String op=exp.substring(exp.indexOf(" ")+1,exp.indexOf(" ")+2);//运算符,是根据运算符前边的空格计算的
privateButtonbtJian;
privateButtonbtMul;
privateButtonbtDivide;
privateButtonbtEqu;
privateButtonbtClear;

android简易计算器的实现

android简易计算器的实现

android简易计算器的实现最近接触了android开发就试着写了⼀个计算器的⼩程序:在xml⽂件中的布局代码如下:1<?xml version="1.0" encoding="utf-8"?>2<LinearLayout xmlns:android="/apk/res/android"3 xmlns:tools="/tools"4 android:id="@+id/activity_ji_suan02"5 android:layout_width="match_parent"6 android:layout_height="match_parent"7 android:orientation="vertical"8 tools:context="com.example.whs.sample01_1_activity.JiSuanActivity02">910<TextView11android:id="@+id/tv"12 android:layout_width="match_parent"13 android:layout_height="40dp"14 android:textSize="30dp"15 android:text="0"16 android:textColor="#ff0000"17 android:gravity="center_vertical|right"18 android:layout_marginRight="5dp"19 android:layout_marginLeft="5dp"20 android:background="#FFFF00"21/>22<!--7 8 9 + -->23<LinearLayout24android:layout_width="match_parent"25 android:layout_height="wrap_content"26 android:paddingTop="5dp"27 android:orientation="horizontal"28>2930<Button31android:id="@+id/Button07"32 android:text="7"33 android:textSize="25dp"34 android:layout_width="80dp"35 android:layout_height="wrap_content"/>36<Button37android:id="@+id/Button08"38 android:text="8"39 android:textSize="25dp"40 android:layout_width="80dp"41 android:layout_height="wrap_content"/>42<Button43android:id="@+id/Button09"44 android:text="9"45 android:textSize="25dp"46 android:layout_width="80dp"47 android:layout_height="wrap_content"/> 48<Button49android:id="@+id/ButtonJia"50 android:text="+"51 android:textSize="25dp"52 android:layout_width="80dp"53 android:layout_height="wrap_content"/> 5455</LinearLayout>5657<!--4 5 6 - -->58<LinearLayout59android:layout_width="match_parent"60 android:layout_height="wrap_content"61 android:paddingTop="5dp"62 android:orientation="horizontal"63>6465<Button66android:id="@+id/Button04"67 android:text="4"68 android:textSize="25dp"69 android:layout_width="80dp"70 android:layout_height="wrap_content"/> 71<Button72android:id="@+id/Button05"73 android:text="5"74 android:textSize="25dp"75 android:layout_width="80dp"76 android:layout_height="wrap_content"/> 77<Button78android:id="@+id/Button06"79 android:text="6"80 android:textSize="25dp"81 android:layout_width="80dp"82 android:layout_height="wrap_content"/> 83<Button84android:id="@+id/ButtonJian"85 android:text="-"86 android:textSize="25dp"87 android:layout_width="80dp"88 android:layout_height="wrap_content"/> 8990</LinearLayout>9192<!--1 2 3 * -->93<LinearLayout94android:layout_width="match_parent"95 android:layout_height="wrap_content"96 android:paddingTop="5dp"97 android:orientation="horizontal"98>99100<Button101android:id="@+id/Button01"102 android:text="1"103 android:textSize="25dp"104 android:layout_width="80dp"105 android:layout_height="wrap_content"/> 106<Button107android:id="@+id/Button02"108 android:text="2"109 android:textSize="25dp"110 android:layout_width="80dp"111 android:layout_height="wrap_content"/> 112<Button113android:id="@+id/Button03"114 android:text="3"115 android:textSize="25dp"116 android:layout_width="80dp"117 android:layout_height="wrap_content"/> 118<Button119android:id="@+id/ButtonCheng"120 android:text="*"121 android:textSize="25dp"122 android:layout_width="80dp"123 android:layout_height="wrap_content"/> 124125</LinearLayout>126127<!--0 C = / -->128<LinearLayout129android:layout_width="match_parent"130 android:layout_height="wrap_content"131 android:paddingTop="5dp"132 android:orientation="horizontal"133>134135<Button136android:id="@+id/Button00"137 android:text="0"138 android:textSize="25dp"139 android:layout_width="80dp"140 android:layout_height="wrap_content"/>141<Button142android:id="@+id/ButtonC"143 android:text="C"144 android:textSize="25dp"145 android:layout_width="80dp"146 android:layout_height="wrap_content"/>147<Button148android:id="@+id/ButtonDeng"149 android:text="="150 android:textSize="25dp"151 android:layout_width="80dp"152 android:layout_height="wrap_content"/>153<Button154android:id="@+id/ButtonChu"155 android:text="/"156 android:textSize="25dp"157 android:layout_width="80dp"158 android:layout_height="wrap_content"/>159160</LinearLayout>161162163164165166</LinearLayout>在activity中实现具体的功能1package com.example.whs.sample01_1_activity;23import android.provider.Settings;4import android.support.v7.app.AppCompatActivity;5import android.os.Bundle;6import android.view.View;7import android.widget.Button;8import android.widget.TextView;9import android.widget.Toast;1011public class JiSuanActivity02 extends AppCompatActivity {1213 TextView tv;14int[] buttons; //数字按钮数组15int result;16int result0;17int result1;1819//按钮对象声明20 Button buttonC;21 Button buttonJia;22 Button buttonJian;23 Button buttonCheng;24 Button buttonChu;25 Button buttonDengyu;2627 String str1; //旧输⼊的值28 String str2; //新输⼊的值2930int flag=0; //计算标志位,0第⼀次输⼊;1加; 2减; 3乘; 4除; 5等于 31 Button temp;3233 @Override34protected void onCreate(Bundle savedInstanceState) {35super.onCreate(savedInstanceState);36 setContentView(yout.activity_ji_suan02);3738 initButton();39//清空按钮点击事件40 buttonC.setOnClickListener(new View.OnClickListener() {41 @Override42public void onClick(View view) {43 str1 = "";44 str2 = "";45 tv.setText("0");46 result = 0;47 result1 = 0;48 result0 = 0;49 flag = 0;50 }51 });5253//监听54for (int i = 0; i < buttons.length; i++){55 temp = getBtnForId(buttons[i]);56 temp.setOnClickListener(new View.OnClickListener() {57 @Override58public void onClick(View view) {59if (flag != 0){60 str1 = "";61 }else {62 str1 = tv.getText().toString().trim();63if (str1.equals("0")){64 str1 = "";65 }66 }6768 str1 = str1 + String.valueOf(((Button)view).getText()); //获取新值69 tv.setText(str1);70 }71 });72 }7374 buttonListener(buttonJia, 1);75 buttonListener(buttonJian, 2);76 buttonListener(buttonCheng, 3);77 buttonListener(buttonChu, 4);7879 buttonDengyu.setOnClickListener(new View.OnClickListener() {80 @Override81public void onClick(View view) {8283 result1 = Integer.parseInt(str1);8485if (flag == 1){86 result = result0 + result1;87 }else if (flag == 2){88 result = result0 - result1;89 }else if (flag == 3){90 result = result0 * result1;91 }else if (flag == 4){92if (result1 == 0){93 Toast.makeText(JiSuanActivity02.this, "除数不能为0", Toast.LENGTH_SHORT).show();94 }else {95 result = result0 / result1;96 }9798 }else if (flag == 0){99 result = result1;100 }101 String str = (result + "").trim();102103if (result1 == 0 && flag == 4){104 str = "错误";105 }106 tv.setText(str);107 Toast.makeText(JiSuanActivity02.this, "结果是:" + result, Toast.LENGTH_SHORT).show(); 108 }109 });110 }111112//初始化控件资源113public void initButton(){114 tv = (TextView)this.findViewById();115 str1 = String.valueOf(tv.getText());116 str2 = "";117 buttonC = getBtnForId(R.id.ButtonC);118 buttonJia = getBtnForId(R.id.ButtonJia);119 buttonJian = getBtnForId(R.id.ButtonJian);120 buttonCheng = getBtnForId(R.id.ButtonCheng);121 buttonChu = getBtnForId(R.id.ButtonChu);122 buttonDengyu = getBtnForId(R.id.ButtonDeng);123124 buttons = new int[]{125 R.id.Button00,R.id.Button01,R.id.Button02,126 R.id.Button03,127 R.id.Button04,R.id.Button05,R.id.Button06,128 R.id.Button07,R.id.Button08,R.id.Button09129 };130 }131//根据id获取Button132public Button getBtnForId(int rID){133 Button btn = (Button)this.findViewById(rID);134return btn;135 }136//按钮监听137public void buttonListener(Button button, final int id){138 button.setOnClickListener(new View.OnClickListener() { 139 @Override140public void onClick(View view) {141 String str = tv.getText().toString().trim();142 result0 = Integer.parseInt(str);143//tv.setText("");144 flag = id;145 }146 });147 }148 }。

安卓计算器设计报告

安卓计算器设计报告

数学与信息技术学院嵌入式系统课程设计报告设计题目:数字计算器的设计与实现班级:学号:姓名:指导教师:完成日期:成绩:目录1 绪论 (1)1.2 研究的范围及达到的技术要求 (1)1.3 解决的主要问题 (1)1.4 设计的指导思想 (1)2 需求分析 (2)2.1 设计需求分析 (2)2.2 系统目标 (2)2.3 主体功能 (2)2.4 开发环境 (2)3 总体设计 (3)3.1 程序流程和系统功能设计 (3)3.1.1 程序流程设计 (3)3.3 程序设计的基本思路 (4)3.3.2 总体布局 (5)3.3.3 按钮事件处理 (6)4 详细设计 (6)4.1 输入模块详细设计 (6)4.2 显示模块详细设计 (7)4.3 计算模块详细设计 (7)5 编码 (8)5.1 用户界面代码设计 (8)5.1.1 activity_main.xml布局文件 (8)5.1.2 MainActivity.java主要功能文件 (9)6 结论 (12)6.1 实现的功能 (12)6.2 主要的问题 (12)数字计算器的设计与实验1 绪论1.1 设计的目的及意义(1)本课程设计的目的是通过开发一个数字计算机器,了解嵌入式产品开发的主要步骤,包括需求分析、系统结构设计、图形界面设计、驱动设计、功能优化、系统测试等,培养独立完成比较复杂的实际设计的能力。

(2)本课程设计主要是实现Android计算器,用于Android系统的用户的使用,本计算器可以实现加、减、乘、除、开方、平方等运算功能,方便了用户对于一些简单数据的计算,节省了用户的时间。

1.2 研究的范围及达到的技术要求本课程设计主要研究计算器的实现方法,应达到计算器界面友好,方便使用,具有基本的加、减、乘、除功能,支持小数运算,具有退格功能,能够删除最后一个输入,具有清除功能,即“C”。

1.3解决的主要问题随着信息时代的步伐加快,日常生活的开支、大额数字、多倍小数等的计算都需要计算器的帮助,处理数字的开方、平方同样也离不开计算器。

基于安卓的计算器的设计与实现

基于安卓的计算器的设计与实现

基于安卓的计算器的设计与实现在设计和实现基于安卓的计算器时,需要考虑以下几个重要的方面:用户界面设计、计算逻辑实现和功能扩展。

首先,用户界面设计是一个计算器的重要组成部分。

一个简洁直观、易于使用的界面可以提供良好的用户体验。

可以考虑使用标准计算器的布局,包括数字键盘、运算符按钮和显示结果的文本框。

此外,还可以添加一些额外的功能,比如一键清除按钮、括号按钮和科学计算模式切换按钮等。

考虑到不同屏幕尺寸和定制化需求,应该使用相对布局或者网格布局来放置UI元素。

其次,计算逻辑实现是计算器的核心部分。

需要支持基本的四则运算,包括加法、减法、乘法和除法。

为了实现连续运算和操作优先级,可以使用栈或者逆波兰表示法。

在用户输入数字和运算符时,应该及时更新显示结果的文本框。

另外,还应该考虑异常情况的处理,比如除数为零的情况。

最后,功能扩展是一个好的设计的关键。

除了基本的四则运算,还可以考虑添加一些其他功能,比如开方、求平方、取余、倒数、阶乘等。

另外,还可以添加一个历史记录功能,记录用户的计算过程和结果,方便用户查看和回顾。

此外,还可以添加一个单位转换功能,支持常见的长度、重量、温度、时间、速度等单位之间的转换。

在实际开发中,可以使用Android Studio作为开发工具。

Android Studio提供了丰富的界面设计工具和模拟器,可以方便地进行界面布局和调试。

可以使用Java语言进行开发,使用Android提供的API来处理用户输入和展示结果。

在代码实现中,可以使用按钮点击事件来处理用户输入。

当用户点击数字按钮时,将所点击的数字添加到一个临时变量中,当用户点击运算符按钮时,将临时变量中的数字和运算符添加到运算式中,并清空临时变量。

当用户点击等号按钮时,根据运算式中的数字和运算符进行实际的计算,并将结果显示在结果文本框中。

当用户点击清空按钮时,将运算式和结果文本框清空。

除了基本逻辑实现外,还可以进行一些优化和改进。

基于Android平台的简易计算器设计

基于Android平台的简易计算器设计
b u t t o n 0=( B u t t o n ) i f n d Vi e wB y l d ( R . i d . b u t t o n 0 1 :
O C l i c k L i s t e n e r {
p u b l i c v o i d o n Cl i c k ( Vi e w v ){
3 软 件 测 试 结 果
设 汁 并 编 写 好 的 程 序 叮 以 究 荚 的 在 虚 拟 机 上 运 行 ,并 完 成 基 本 的加 减 乘 除运 算 , 将
结 果 显 示 在 文本 框 内 。 效 果 如 J 刭所 示 。
对来说都有 繁琐 ,放采取此种布局方式 ,关
键代码如下 :
也 自然 也很 庞 大 在 此 基础 上 , 本人设 计 了一款 简 易计 算 器,可
以在 A n d r o i d平 台上 很 好 的运 行 , 能 完 成 基 本 的 加 减 乘 除 以 及 小 数 运 算,可 以 为有 需要 的人 提供 一
定 的 便 利
【 关键 词 】 智 能 手 机 A n d r o i d 计 算 器
( T a b l e L a y o u t ) 、绝 对布局 ( Ab s o l u t e L a y o u t ) 相
在每个组什都存代码 f I 找到之 后,就 需要绑 定 相应的监听器柬 没定按 卜 此按 的相关 动作 ,
绑 定 监 听 器 需 要 Ac t i v i t y类 F声 明 一 个 内部
T = 的 哭键 代 码 如 一 :
p u b l i c c l a s s C a c u l a t o r e x t e n d s A c t i v i t y{

制作一个简易计算器——基于AndroidStudio实现

制作一个简易计算器——基于AndroidStudio实现

制作⼀个简易计算器——基于AndroidStudio实现⼀个计算器Android程序的源码部分分为主⼲和细节两部分。

⼀、主⼲1. 主⼲的构成计算器的布局事件(即计算器上的按钮、⽂本框)监听实现计算2. 详细解释 假设我们的项⽬名为Calculator,⽽布局名称(Layout Name)为默认的activity_main 。

即设置如下图所⽰: 在这种前提下,有:设置计算器布局的⽂件:Calculator/app/src/main/res/layout/activity_main.xml事件监听和计算实现在同⼀个⽂件⾥:Calculator/app/src/main/java/下的⼀个⼦⽬录⾥的MainActivity.java 即如下图所⽰:计算器布局代码(写在activity_main.xml⽂件⾥):1<?xml version="1.0" encoding="utf-8"?>2<ScrollView xmlns:android="/apk/res/android"3 android:layout_width="fill_parent"4 android:layout_height="wrap_content"5>6<LinearLayout7android:layout_width="fill_parent"8 android:layout_height="fill_parent"9 android:orientation="vertical">10<EditText11android:id="@+id/input"12 android:layout_width="fill_parent"13 android:layout_height="wrap_content"14 android:layout_gravity="center"15 android:editable="false"16 android:hint="@string/shuru"/>1718<EditText19android:id="@+id/output"20 android:layout_width="fill_parent"21 android:layout_height="wrap_content"22 android:layout_gravity="center"23 android:editable="true"24 android:gravity="right"25 android:hint="@string/shuchu"/>2627<RelativeLayout28android:layout_width="fill_parent"29 android:layout_height="wrap_content">3031<Button32android:id="@+id/seven"33 android:layout_width="80dp"34 android:layout_height="70dp"35 android:layout_alignParentLeft="true"36 android:text="@string/seven"37 android:textSize="40sp"/>3839<Button44 android:text="@string/eight"45 android:textSize="40sp"/>4647<Button48android:id="@+id/nine"49 android:layout_width="80dp"50 android:layout_height="70dp"51 android:layout_toRightOf="@id/eight"52 android:text="@string/nine"53 android:textSize="40sp"/>5455<Button56android:id="@+id/add"57 android:layout_width="80dp"58 android:layout_height="70dp"59 android:layout_alignParentRight="true"60 android:layout_toRightOf="@id/nine"61 android:text="@string/add"62 android:textSize="40sp"/>6364<Button65android:id="@+id/four"66 android:layout_width="80dp"67 android:layout_height="70dp"68 android:layout_alignParentLeft="true"69 android:layout_below="@id/seven"70 android:text="@string/four"71 android:textSize="40sp"/>7273<Button74android:id="@+id/five"75 android:layout_width="80dp"76 android:layout_height="70dp"77 android:layout_below="@id/eight"78 android:layout_toRightOf="@id/four"79 android:text="@string/five"80 android:textSize="40sp"/>8182<Button83android:id="@+id/six"84 android:layout_width="80dp"85 android:layout_height="70dp"86 android:layout_below="@id/nine"87 android:layout_toRightOf="@id/five"88 android:text="@string/six"89 android:textSize="40sp"/>9091<Button92android:id="@+id/subtract"93 android:layout_width="80dp"94 android:layout_height="70dp"95 android:layout_alignParentRight="true"96 android:layout_below="@id/add"97 android:layout_toRightOf="@id/six"98 android:text="@string/subtract"99 android:textSize="40sp"/>100101<Button102android:id="@+id/one"103 android:layout_width="80dp"104 android:layout_height="70dp"105 android:layout_alignParentLeft="true" 106 android:layout_below="@id/four"107 android:text="@string/one"108 android:textSize="40sp"/>109110<Button111android:id="@+id/two"112 android:layout_width="80dp"113 android:layout_height="70dp"114 android:layout_below="@id/five"115 android:layout_toRightOf="@id/one" 116 android:text="@string/two"117 android:textSize="40sp"/>118119<Button120android:id="@+id/three"121 android:layout_width="80dp"122 android:layout_height="70dp"123 android:layout_below="@id/six"128<Button129android:id="@+id/multiply"130 android:layout_width="80dp"131 android:layout_height="70dp"132 android:layout_alignParentRight="true" 133 android:layout_below="@id/subtract" 134 android:layout_toRightOf="@id/three" 135 android:text="@string/multiply"136 android:textSize="40sp"/>137138<Button139android:id="@+id/zero"140 android:layout_width="80dp"141 android:layout_height="70dp"142 android:layout_alignParentLeft="true" 143 android:layout_below="@id/one"144 android:text="@string/zero"145 android:textSize="40sp"/>146147<Button148android:id="@+id/clear"149 android:layout_width="80dp"150 android:layout_height="70dp"151 android:layout_below="@id/two"152 android:layout_toRightOf="@id/zero" 153 android:text="@string/clear"154 android:textSize="40sp"/>155156<Button157android:id="@+id/result"158 android:layout_width="80dp"159 android:layout_height="70dp"160 android:layout_below="@id/three"161 android:layout_toRightOf="@id/clear" 162 android:text="@string/result"163 android:textSize="40sp"/>164165<Button166android:id="@+id/divide"167 android:layout_width="80dp"168 android:layout_height="70dp"169 android:layout_alignParentRight="true" 170 android:layout_below="@id/multiply" 171 android:layout_toRightOf="@id/result" 172 android:text="@string/divide"173 android:textSize="40sp"/>174175<Button176android:id="@+id/dot"177 android:layout_width="80dp"178 android:layout_height="70dp"179 android:layout_alignParentLeft="true" 180 android:layout_below="@id/zero"181 android:text="@string/dot"182 android:textSize="40sp"/>183<Button184android:id="@+id/writeButton"185 android:layout_width="wrap_content" 186 android:layout_height="wrap_content" 187 android:layout_alignParentLeft="true" 188 android:layout_below="@id/dot"189 android:text="@string/write"190 android:textSize="40sp"/>191<Button192android:id="@+id/readButton"193 android:layout_width="wrap_content" 194 android:layout_height="wrap_content" 195 android:layout_alignParentRight="true" 196 android:layout_below="@id/dot"197 android:text="@string/read"198 android:textSize="40sp"/>199200<CheckBox201android:id="@+id/appendBox"202 android:text="@string/appendBox"203 android:layout_width="wrap_content" 204 android:layout_height="wrap_content" 205 android:layout_alignParentBottom="true" 206 android:layout_toLeftOf="@+id/divide" 207 android:layout_toStartOf="@+id/divide"212213<EditText214215android:layout_width="match_parent"216 android:layout_height="wrap_content"217 android:id="@+id/textView"/>218219<EditText220221android:layout_width="match_parent"222 android:layout_height="wrap_content"223 android:id="@+id/displayView"/>224225<EditText226android:id="@+id/errorzero"227 android:layout_width="fill_parent"228 android:layout_height="wrap_content"229 android:layout_gravity="center"230 android:editable="false"231 android:gravity="center"232/>233<EditText234android:id="@+id/resultText"235 android:layout_width="fill_parent"236 android:layout_height="wrap_content"237 android:layout_gravity="center"238 android:editable="false"239 android:gravity="left"240 android:text="@string/resultText"241/>242</LinearLayout>243</ScrollView>View Code事件监听和实现计算代码(写在MainActivity.java⽂件⾥)1package com.example.lenovo.calculator;2345import android.app.Activity;6import android.content.Context;7import android.os.Bundle;8import android.view.View;9import android.view.View.OnClickListener;10import android.widget.Button;11import android.widget.CheckBox;12import android.widget.EditText;1314import java.io.FileInputStream;15import java.io.FileNotFoundException;16import java.io.FileOutputStream;17import java.io.IOException;1819public class MainActivity extends Activity {20/**21 * Called when the activity is first created.22*/23private EditText output = null;24private EditText input = null;25private Button btn0 = null;26private Button btn1 = null;27private Button btn2 = null;28private Button btn3 = null;29private Button btn4 = null;30private Button btn5 = null;31private Button btn6 = null;32private Button btn7 = null;33private Button btn8 = null;34private Button btn9 = null;35private Button btnadd = null;36private Button btnsubtract = null;37private Button btnmultiply = null;38private Button btndivide = null;39private Button btnclear = null;40private Button btnresult = null;41private Button btndot = null;46private Button writeButton = null;47private Button readButton = null;48private CheckBox appendBox = null;49private EditText textView = null;50private EditText displayView = null;51public String FILE_NAME = "fileDemo.txt";525354private String str = "";//保存数字55private String strold = "";//原数字56private char act = ' ';//记录“加减乘除等于”符号57private int count = 0;//判断要计算的次数,如果超过⼀个符号,先算出来⼀部分58private Float result = null;//计算的输出结果59private Boolean errBoolean = false;//有错误的时候为true,⽆错为false60private Boolean flagBoolean = false;//⼀个标志,如果为true,可以响应运算消息,如果为false,不响应运算消息,只有前⾯是数字才可以响应运算消息 61private Boolean flagDot = false; //⼩数点标志位62636465 @Override66public void onCreate(Bundle savedInstanceState) {67super.onCreate(savedInstanceState);68 setContentView(yout.activity_main);6970 output = (EditText) findViewById(R.id.output);71 input = (EditText) findViewById(R.id.input);7273 errorzero = (EditText) findViewById(R.id.errorzero);74 resultText = (EditText) findViewById(R.id.resultText);75 writeButton = (Button) findViewById(R.id.writeButton);76 readButton = (Button) findViewById(R.id.readButton);77 textView = (EditText) findViewById(R.id.textView);78 displayView = (EditText) findViewById(R.id.displayView);79 appendBox = (CheckBox) findViewById(R.id.appendBox);8081 btn0 = (Button) findViewById(R.id.zero);82 btn1 = (Button) findViewById(R.id.one);83 btn2 = (Button) findViewById(R.id.two);84 btn3 = (Button) findViewById(R.id.three);85 btn4 = (Button) findViewById(R.id.four);86 btn5 = (Button) findViewById(R.id.five);87 btn6 = (Button) findViewById(R.id.six);88 btn7 = (Button) findViewById(R.id.seven);89 btn8 = (Button) findViewById(R.id.eight);90 btn9 = (Button) findViewById(R.id.nine);91 btnadd = (Button) findViewById(R.id.add);92 btnsubtract = (Button) findViewById(R.id.subtract);93 btnmultiply = (Button) findViewById(R.id.multiply);94 btndivide = (Button) findViewById(R.id.divide);95 btnclear = (Button) findViewById(R.id.clear);96 btnresult = (Button) findViewById(R.id.result);97 btndot = (Button) findViewById(R.id.dot);98//设置按钮侦听事件99 btn0.setOnClickListener(listener);100 btn1.setOnClickListener(listener);101 btn2.setOnClickListener(listener);102 btn3.setOnClickListener(listener);103 btn4.setOnClickListener(listener);104 btn5.setOnClickListener(listener);105 btn6.setOnClickListener(listener);106 btn7.setOnClickListener(listener);107 btn8.setOnClickListener(listener);108 btn9.setOnClickListener(listener);109//执⾏运算110 btnadd.setOnClickListener(listener);111 btnsubtract.setOnClickListener(listener);112 btnmultiply.setOnClickListener(listener);113 btndivide.setOnClickListener(listener);114 btnclear.setOnClickListener(listener);115 btnresult.setOnClickListener(listener);116117 btndot.setOnClickListener(listener);118119 writeButton.setOnClickListener(writelistener);120 readButton.setOnClickListener(readlistener);121122123// ATTENTION: This was auto-generated to implement the App Indexing API.124// See https://g.co/AppIndexing/AndroidStudio for more information.125 }130public void onClick(View v) {131// TODO Auto-generated method stub132switch (v.getId()) {133//输⼊数字134case R.id.zero:135 num(0);136break;137case R.id.one:138 num(1);139break;140case R.id.two:141 num(2);142break;143case R.id.three:144 num(3);145break;146case R.id.four:147 num(4);148break;149case R.id.five:150 num(5);151break;152case R.id.six:153 num(6);154break;155case R.id.seven:156 num(7);157break;158case R.id.eight:159 num(8);160break;161case R.id.nine:162 num(9);163break;164165case R.id.dot:166 dot();167break;168//执⾏运算169case R.id.add:170 add();171break;172case R.id.subtract:173 sub();174break;175case R.id.multiply:176 multiply();177break;178case R.id.divide:179 divide();180break;181case R.id.clear:182 clear();183break;184//计算结果185case R.id.result:186 result();187if (!errBoolean && flagBoolean) {188 output.setText(String.valueOf(result));189 }190 resultText.setText(strold + act + str + "=" + result+" "); 191break;192193default:194break;195196 }197 input.setText(strold + act + str);198 output.setText(String.valueOf(result));199200201 }202 };203204private OnClickListener writelistener = new OnClickListener() {205 @Override206public void onClick(View view) {207//textView.setText("");208209 FileOutputStream fos = null;214 fos = openFileOutput(FILE_NAME, Context.MODE_PRIVATE); 215 }216 String text = resultText.getText().toString();217 fos.write(text.getBytes());218 textView.setText("⽂件写⼊成功,写⼊长度:" + text.length()); 219//resultText.setText("");220221 } catch (FileNotFoundException e) {222 e.printStackTrace();223 } catch (IOException e) {224 e.printStackTrace();225 }226finally {227if (fos != null)228try {229 fos.flush();230 fos.close();231 } catch (IOException e) {232 e.printStackTrace();233 }234 }235 }236 };237private OnClickListener readlistener = new OnClickListener() {238 @Override239public void onClick(View view) {240241 displayView.setText("");242 FileInputStream fis = null;243try {244 fis = openFileInput(FILE_NAME);245if (fis.available() == 0) {246return;247 }248byte[] readBytes = new byte[fis.available()];249while (fis.read(readBytes) != -1) {250251 }252 String text = new String(readBytes);253 displayView.setText(text);254 textView.setText("⽂件读取成功,写⼊长度:" + text.length()); 255256 } catch (FileNotFoundException e) {257 e.printStackTrace();258 } catch (IOException e) {259 e.printStackTrace();260 }261262 }263 };264265private void dot() {266// TODO Auto-generated method stub267268if (!flagDot) {269 str = str + ".";270 flagBoolean = false;271 flagDot = true;272 }273 }274275private void clear() {276// TODO Auto-generated method stub277 str = strold = "";278 count = 0;279 act = ' ';280 result = null;281 flagBoolean = false;282 flagDot = false;283 input.setText(strold + act + str);284 output.setText("");285 errorzero.setText("");286 displayView.setText("");287 textView.setText("");288 resultText.setText("");289 }290291private void divide() {292// TODO Auto-generated method stub293if (flagBoolean) {299300private void multiply() {301// TODO Auto-generated method stub 302if (flagBoolean) {303 check();304 act = '*';305 flagBoolean = false;306 }307 }308309private void sub() {310// TODO Auto-generated method stub 311if (flagBoolean) {312 check();313 act = '-';314 flagBoolean = false;315 }316 }317318private void add() {319// TODO Auto-generated method stub 320if (flagBoolean) {321 check();322 act = '+';323 flagBoolean = false;324 }325 }326327private void check() {328// TODO Auto-generated method stub 329if (count >= 1) {330 result();331 str = String.valueOf(result);332 }333 strold = str;334 str = "";335 count++;336 flagDot = false;337 errorzero.setText("");338 }339340//计算输出结果341private void result() {342// TODO Auto-generated method stub 343if (flagBoolean) {344 Float a, b;345346 a = Float.parseFloat(strold);347 b = Float.parseFloat(str);348349if (b == 0 && act == '/') {350 clear();351 errorzero.setText("除数不能为零!"); 352//output.setText("除数不能为零!"); 353354355//errBoolean=true;356 }357358359if (!errBoolean) {360switch (act) {361case '+':362 result = a + b;363break;364case '-':365 result = a - b;366break;367case '*':368 result = a * b;369break;370case '/':371 result = a / b;372break;373374default:375break;376 }377 }383private void num(int i) {384// TODO Auto-generated method stub385 str = str + String.valueOf(i);386 flagBoolean = true;387 errorzero.setText("");388 }389390 }View Code⼆、细节 仅仅将主⼲部分代码copy下来并不能运⾏程序,因为主⼲代码调⽤了⼀些⽂件的代码,这些⽂件就是我们所说的细节。

基于android的科学计算器的课设

基于android的科学计算器的课设

基于android的科学计算器的课设
基于Android的科学计算器的课设
随着科技的不断发展,计算器已经成为了人们日常生活中必不可少的工具之一。

而随着科学技术的不断进步,人们对计算器的要求也越来越高,特别是在科学计算方面。

因此,基于Android的科学计算器的课设就应运而生。

基于Android的科学计算器的课设需要具备基本的计算功能,如加减乘除等。

同时,还需要具备科学计算功能,如三角函数、对数函数、指数函数等。

这些功能的实现需要借助于Android平台提供的API,如Math类等。

基于Android的科学计算器的课设还需要具备良好的用户界面设计。

用户界面设计应该简洁明了,易于操作。

同时,还需要考虑到不同屏幕尺寸的适配问题,以保证在不同的设备上都能够正常使用。

除此之外,基于Android的科学计算器的课设还需要具备一些高级功能,如历史记录、记忆功能等。

历史记录功能可以记录用户的计算历史,方便用户查看和修改。

记忆功能可以记录用户的某些计算结果,方便用户下次使用时直接调用。

基于Android的科学计算器的课设还需要考虑到一些安全问题。

例如,用户输入的数据可能存在恶意代码,需要进行过滤和验证。


时,还需要考虑到数据的保密性,以防止用户的隐私泄露。

基于Android的科学计算器的课设需要具备基本的计算功能和科学计算功能,良好的用户界面设计,高级功能和安全性保障。

只有这样,才能够满足用户的需求,成为一款优秀的科学计算器。

Android开发实战:创建一个简单的计算器应用(三)

Android开发实战:创建一个简单的计算器应用(三)

Android开发实战:创建一个简单的计算器应用随着智能手机的普及,Android操作系统逐渐成为了一个重要的移动应用平台。

作为开发者,学习并掌握Android应用开发技术,可以帮助我们打造出各类实用的移动应用。

本文将介绍如何创建一个简单的计算器应用,以帮助读者入门Android开发。

1. 前言计算器应用作为一种基础的工具类应用,可以在日常生活中得到很多实际应用场景。

通过自己动手开发一个计算器应用,不仅可以巩固所学的Android开发知识,同时也能够提升自己的动手能力。

2. 准备工作首先,我们需要安装Android开发环境。

Android开发主要使用Java语言进行编程,并依赖于Android SDK(开发工具包)。

在安装Android Studio之后,我们可以创建一个新的Android项目,该项目将用于我们的计算器应用。

3. 创建UI界面UI界面是用户与应用进行交互的重要组成部分。

在我们的计算器应用中,我们可以使用Android的布局文件来定义我们的UI界面。

可以使用LinearLayout或者RelativeLayout等布局容器来组织UI元素的摆放位置。

通过设置按钮的宽高、位置等属性,我们可以让界面看起来更加美观。

同时,我们还可以为按钮添加点击事件,以实现按钮的功能。

4. 实现计算逻辑在计算器应用中,最重要的部分是实现计算逻辑。

我们可以为不同的按钮设置不同的点击事件,以实现加减乘除等运算功能。

在事件触发的回调函数中,我们可以获取用户输入的数字和运算符,然后进行相应的计算逻辑处理,并将结果显示在屏幕上。

为了方便计算逻辑的实现,我们可以使用Java提供的数学库函数或者自定义方法来完成运算操作。

通过合理地组织代码,我们可以保证计算逻辑的正确性和效率。

5. 错误处理和边界情况在实际开发中,一个好的应用应该能够处理各种错误和边界情况。

例如,除数为零、输入格式不正确等情况都应该进行适当的提示。

为了保证应用的稳定性和可靠性,我们可以使用条件判断和异常处理等技术手段,来处理异常情况。

Android平台BMI计算的设计与实现

Android平台BMI计算的设计与实现

Android平台BMI测试精灵课设课程设计的题目Android平台BMI指数计算器的设计与实现<第一章> 需求分析<一> 任务概述BMI程序中需要主界面, 各种其他界面, 所以要很好的将各个界面的连接, 可以从点击按钮连接, 也可以用手势连接下一个界面。

对于音乐图片的选择要能结合用户, 和审美的观念。

尽量做出的界面美观, 让用户能很好的使用。

对于按钮的使用, 如果能了解按钮的各种参数, 也能将一个界面设计的很漂亮首先必须了解, JAVA是面向对象的编程语言, 所以掌握好Java的基本语句是很重要的。

1清楚掌握基本数据类型, 在BMI中因为是大量处理各种类型的数据, 所以对数据类型的变量要求比较高。

2掌握JAVA画图函数的使用;3要掌握android的布局函数;4掌握android的debug调试功能的应用, 能够及时排除错误。

5 要能将java知识和android必要知识有机的结合;根据以上调查分析, 可以给出其现行业务流程图<二>功能需求经过以上详细的用户调查, 在现行业务流程和数据分析的基础上, 基本可以确定系统设计必须达到的目标。

以下是BMI必须具备的功能:1.计算BMI值并存储计算结果及计算日期;2.根据计算所得BMI值给用户称赞或警告提示(动画或音频、图片), 并给出相应的建议;向用户图形化展示指定时间段内用户BMI值得变化情况, 可以采用折线图或柱状图展示;<三>性能需求为了保证系统能够稳定、可靠的运行, BMI应该满足以下的性能需求:1.处理的准确性和及时性处理的准确性和及时性是BMI的必要性能。

在系统设计和开发过程中, 要充分考虑系统当前和将来可能承受的工作量, 使系统的处理能力和响应时间能够满足用户对信息处理的需求。

2.要能加入音乐以及动画效果音乐和动画对一款Android软件是必须的, 能让用户不仅有视觉的体验, 更要有听觉的体验, 让用户能喜欢。

(完整版)基于Android计算器的设计与应用毕业论文

(完整版)基于Android计算器的设计与应用毕业论文

(完整版)基于Android计算器的设计与应⽤毕业论⽂北京北⼤⽅正软件技术学院毕业设计(论⽂)题⽬:基于Android计算器的设计与应⽤系别:软件⼯程分院专业:软件技术学号:姓名:王可可指导⽼师:李强完成⽇期:2014年5 ⽉20 ⽇北京北⼤⽅正软件技术学院毕业设计(论⽂)成绩评定表(理科)年级 11级专业软件技术姓名王可可学号论⽂题⽬:基于Android计算器的设计与应⽤指导教师:李强项⽬评分标准优秀良好合格不合格选题优秀:选题有重要理论意义和实际价值;良好:选题有较强理论意义和实际价值;合格:选题有⼀定理论意义和实际价值;不合格:选题⽋妥。

基础知识优秀:有坚实的理论基础和系统深⼊的专业知识;良好:有较坚实的理论基础和系统深⼊的专业知识;合格:有⼀定的理论基础和专业知识;不合格:基础理论不够全⾯,专业知识不系统。

实践能⼒优秀:体现出较强的实践⼯作能⼒;良好:体现出较好的实践⼯作能⼒;合格:体现出⼀定的实践⼯作能⼒;不合格:体现出⼯作能⼒较差。

写作能⼒优秀:条理清楚,层次分明,⽂笔流畅,学风严谨;良好:条理性好,层次分明,⽂字通顺,⼯作认真;合格:条理较好,层次较分明,⽂字较通顺;不合格:条理不清,写作较差。

论⽂综合评价优秀良好合格不合格指导教师评定意见签字:年⽉⽇毕业设计领导⼩组签字签字:年⽉⽇摘要⽬前⼿机可以说是普及率⾮常⾼的电⼦设备了,由于其便于携带,使⽤⽅便,资费适中等等原因,现在⼿机已经在⼀定程度开始代替固定电话的通话功能,以及⼀些原来电脑软件上的功能了。

⼿机上的软件也随着⼿机的发展变得丰富起来了,时⾄今⽇已经出现了很多专门制作⼿机软件的公司,虽然制作的多是游戏软件,但是⼀些辅助性的⼯具软件也有了很多。

⼿机软件简单说就是可以安装在⼿机上的软件,作⽤⾃然是扩展⼿机的原始功能,使⼿机变得更加的实⽤。

但是⼿机的软件需要安装到相应的系统中才能完美的运⾏。

正是由于考虑到以上这些情况,Android系统是现今⽐较流⾏的⼿机系统,所以本系统选择了java语⾔来作为开发语⾔。

基于android的计算器毕业设计报

基于android的计算器毕业设计报

基于Android的计算器毕业设计报告一、引言随着移动设备的普及,人们对于计算器的需求已经不再局限于桌面电脑。

特别是在Android平台上,由于其开放性和灵活性,使得开发人员可以方便地为其开发各种应用。

本次毕业设计就是开发一款基于Android平台的计算器应用,以满足人们在移动设备上进行基本数学计算的需求。

二、系统分析1.功能需求:本计算器应用需要满足基本数学计算需求,包括加减乘除四则运算,以及括号、百分比、平方、立方等特殊运算。

同时,还需要提供清除、撤销等便捷操作。

2.性能需求:为了保证应用的流畅性和稳定性,需要保证应用的响应速度和计算准确性。

同时,考虑到移动设备的电池寿命,还需要优化电量消耗。

3.用户界面需求:界面需要简洁明了,易于操作。

色彩和图标设计也需要符合Android平台的规范和用户习惯。

三、系统设计1.界面设计:采用Material Design风格,主界面包括数字按键区和操作符选择区。

为了方便用户操作,还添加了滑动输入功能,用户可以通过滑动数字或运算符来选择所需的数字或运算符。

2.算法设计:为了保证计算的准确性,我们采用了双精度浮点数存储数据,并使用Java的BigDecimal类进行运算。

这样既可以保证计算的精度,又可以避免由于浮点数运算产生的误差。

3.数据库设计:为了保存用户的计算历史记录,我们使用了Android的SQLite数据库来存储数据。

每个记录包括计算式和计算结果两个字段。

四、系统实现1.界面实现:我们使用了Android的原生开发方式,通过XML布局文件定义界面结构,通过Java代码实现界面逻辑。

同时,为了提高用户体验,我们还添加了一些动画效果和音效。

2.算法实现:我们使用了Java的BigDecimal类进行数学运算。

通过BigDecimal的multiply()和divide()方法可以实现乘法和除法运算,通过add()和subtract()方法可以实现加法和减法运算。

基于安卓的计算器的设计与实现

基于安卓的计算器的设计与实现
<Button
android:id="@+id/button5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/button4"
android:layout_alignBottom="@+id/button4"
2.
2.1
根据需求,符合用户的实际要求,系统应实现以下功能:计算器界面友好,方便使用,,具有基本的加、减、乘、除功能,能够判断用户输入运算数是否正确,支持小数运算,具有清除功能。
图2.1系统功能图
整个程序基于Android技术开发,除总体模块外主要分为输入模块、显示模块以及计算模块这三大部分。在整个系统中总体模块控制系统的生命周期,输入模块部分负责读取用户输入的数据,显示模块部分负责显示用户之前输入的数据以及显示最终的计算结果,计算模块部分负责进行数据的运算以及一些其他的功能。具体的说,总体模块的作用主要是生成应用程序的主类,控制应用程序的生命周期。
android:layout_marginTop="17dp"
android:ems="10"/>
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"

基于android的计算器毕业设计报告

基于android的计算器毕业设计报告

基于android的计算器毕业设计报告1. 引言计算器是一种常用的电子设备,用于进行各种数学计算和运算,如加减乘除、平方根、百分比等。

随着智能手机的普及,人们越来越倾向于使用手机上的计算器应用进行数学计算,因此开发一款基于Android平台的计算器应用成为一项有意义的毕业设计。

2. 设计目标本计算器应用的设计目标是满足用户对于高效、准确计算需求的同时,具备友好的用户界面和良好的用户体验。

3. 功能设计3.1 基本计算功能用户可以通过输入数字和运算符,进行基本的加减乘除运算。

计算器应能正确解析用户输入的表达式,并给出准确的结果。

3.2 科学计算功能计算器还应该具备科学计算功能,如平方根、立方根、指数运算、对数运算等。

用户可以通过在界面上选择相应的按钮进行科学计算。

3.3 历史记录功能计算器应能保存用户的历史计算记录,以便用户可以回顾之前的计算过程和结果。

用户可以随时查看特定的历史记录,并可以清除历史记录。

3.4 单位转换功能计算器还应该具备单位转换功能,如长度单位之间的转换,重量单位之间的转换等。

用户可以在界面上选择需要进行的单位转换,并输入相应的数值,计算器将给出转换后的结果。

4. 用户界面设计4.1 主界面主界面应该简洁清晰,并具备直观明了的操作按钮,供用户选择进行不同的计算。

4.2 科学计算界面科学计算界面应该设计为可选展示的,用户可以通过选择按钮在主界面和科学计算界面之间切换。

4.3 历史记录界面历史记录界面应该能够展示用户之前的计算过程和结果,并提供删除历史记录的功能。

4.4 单位转换界面单位转换界面应该设计为可选展示的,用户可以通过选择按钮在主界面和单位转换界面之间切换。

5. 开发技术和工具本计算器应用基于Android平台进行开发,开发工具可选用Android Studio。

开发语言选择Java,使用Android SDK进行开发。

设计界面可以使用XML或者Android布局进行设计。

基于安卓开发的计算器课程设计报告

基于安卓开发的计算器课程设计报告

大庆师范学院《ANDROID应用设计》课程设计报告题目:简易计算器专业班级:计算机科学与技术一班设计者:\\\\\\\\\\\\\\\\\\\\\\\\\\\\指导老师:P’P’P’P’设计时间:2016-2017(1)报告完成日期2016 年12月30日1 设计任务及要求设计一款基于Android系统下的计算器,实现一般计算器可以进行的加减乘除算法,以及清零操作。

本人学习Android有近半年的时间。

由于不同的Android 手机有着不同的分辨率,将不同分辨率的图标图片放置在相应位置。

Drawable-hdpi中放置分辨率最高的图标,drawable--ldpi中放置分辨率中等的图标,drawable-mdpi中放置在分辨率最低的图标。

界面设计应该就尽量简洁而美观,应该具有良好的交互性。

在整个过程中,首先应该对输入进行容错处理,这样有利于提高用户体验。

对于用户的按键输入,需要及时的现实在第一个EditView中。

用户在输入过程中,肯定会存在一定的错误,程序设计过程中需要对应用程序进行容错处理。

容错设计比如:在输入过程中小数的话只能有一个小数点,操作符不能连续输入,整数数据的开头不能出现0等等。

在程序设计过程中,需要设计数据结构来存储数字、操作符和容错标记,在本文中使用了栈,对这些数据进行了存储。

2设计原理及总体框图将表达式转为字符串类进行存储。

将表达式的字符串进行处理,将数字和运算符分别存放在两个栈中(也可以使用队列,理论上使用队列更为合理,在这我使用栈来实现)。

由于栈是后进先出的,所以先将两个栈进行逆序。

设计方法来处理两个栈从而得到相应的计算结果。

原理:将操作符设计优先级,乘除优先级设置为2,加减优先级设置为1。

一、从操作符栈中弹出两个操作符,假设为symbol1和symbol2,比较两个操作付的优先级,如果symbol1的优先级大于等于symbol2的则执行二,否则执行三。

二、从数字栈中弹出两个数字,计算这两个数字在操作符symbol1下的运算结果,结束后将结果压入数字栈,将symbol2压入操作符栈,最后返回一。

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

安卓应用程序设计——简易计算器的实现院(系)名称专业名称学生姓名学生学号课程名称2016年6月日1.系统需求分析Android是以Linux为核心的手机操作平台,作为一款开放式的操作系统,随着Android 的快速发展,如今已允许开发者使用多种编程语言来开发Android应用程序,而不再是以前只能使用Java开发Android应用程序的单一局面,因而受到众多开发者的欢迎,成为真正意义上的开放式操作系统。

计算器通过算法实行简单的数学计算从而提高了数学计算的效率,实现计算器的界面优化,使界面更加友好,操作更加方便。

基于android的计算器的设计,系统具有良好的界面;必要的交互信息;简约美观的效果。

使用人员能快捷简单地进行操作,即可单机按钮进行操作,即时准确地获得需要的计算的结果,充分降低了数字计算的难度和节约了时间。

2.系统概要设计2.1计算器功能概要设计根据需求,符合用户的实际要求,系统应实现以下功能:计算器界面友好,方便使用,,具有基本的加、减、乘、除功能,能够判断用户输入运算数是否正确,支持小数运算,具有清除功能。

图2.1系统功能图整个程序基于Android技术开发,除总体模块外主要分为输入模块、显示模块以及计算模块这三大部分。

在整个系统中总体模块控制系统的生命周期,输入模块部分负责读取用户输入的数据,显示模块部分负责显示用户之前输入的数据以及显示最终的计算结果,计算模块部分负责进行数据的运算以及一些其他的功能。

具体的说,总体模块的作用主要是生成应用程序的主类,控制应用程序的生命周期。

输入模块主要描述了计算器键盘以及键盘的监听即主要负责读取用户的键盘输入以及响应触屏的按键,需要监听手机动作以及用指针事件处理方法处理触屏的单击动作。

同时提供了较为直观的键盘图形用户界面。

显示模块描述了计算器的显示区,即该区域用于显示用户输入的数据以及最终的计算结果,同时负责显示一些其他的信息。

计算模块则主要描述了计算器的整体,实现了计算器的界面,负责计算用户输入数据,包括加、减、乘、除等各种功能,记忆数据的相关功能,清零的功能。

图2.2三大模块2.2 输入模块设计系统如果想完成计算器中各种功能,首先用户要能进行数据输入,由于是在触屏手机上开发计算器程序,所以要求输入可以直接使用触屏进行,所以在设计的时候就要充分的考虑这一点。

正是由于考虑到这个特殊的地方,所以在进行模块设计中,选择编写输入模块类的时候会特意选取使用可以支持触屏输入的特殊增强型图形用户界面类。

输入模块主要的任务是描述计算器键盘以及实现键盘的监听,即当用户点击按键或者屏幕的时候监听会去调用相应的处理办法,本模块还需要为系统提供一个较为直观的键盘图形用户界面。

输入模块的功能图如图图2.3输入模块2.3显示模块设计作为手机计算器系统,显示部分也是必不可少的一部分。

没有显示部分就没有办法显示用户输入的数字是否正确,甚至不能显示计算出的结果,由此可见显示模块即包括输入的部分(因个人技术原因不能显示表达式的形式)也包括输出的部分。

显示模块主要完成的任务是描述计算器的显示区,该区域用于显示用户输入的数据以及最终的计算结果和一些其他信息。

同时本模块还将提供调用和设置显示的具体方法总体系统显示模块 计算模块 输入模块图2.4显示模块2.4计算模块设计系统要完成整个的计算器的功能,那么计算模块就是整个系统的重要模块。

没有计算模块系统就不能顺利的完成计算,就无法达到用户的要求。

所以计算模块的设计也是本次系统设计的重点。

系统想要能在屏幕上显示出计算器的样子要有整体的布局。

在本模块中要完成布局的具体设计,使用户能够看到整个计算器的界面。

同时系统想完成计算功能必须要处理用户的输入,当输入模块的监听传到计算模块中时,计算模块就要根据相应的方法进行进一步的处理。

图2.5计算模块3.设计与实现部分3.1应用程序构成Android应用程序一般是由Activity、Serviece、Content Provider、Intent、Intent Receiver、Notification六个组件构成。

但并非每一个Android应用程序都包含这六个组件。

(1)Activity(活动):应用程序的表示层。

Activity是Android的基本组件。

每一个activity 代表一个单独的屏幕。

每一个activity都是继承于Activity的独立类。

这个activity类将会显示出几个Views控件组成的用户接口,并对事件作出响应。

Android使用了Intent,实现在屏幕与屏幕之间跳转。

Activity跳转时只需要调用startActivity(Intent myIntent)方法。

然后,系统会在所有安装的应用程序中定义的IntentFilter中查找,找到最匹配myIntent的Intent 对应的activity。

新的activity接收到myIntent的通知后,开始启动运行。

当startActivity方法被调用将触发解析myIntent的动作,这个机制提供了两个关键的好处:能够重复利用从其他组件中以Intent的形式产生的一个请求和可以在任何时候被一个具有相同IntentFilter 的新的startActivity取代。

(2)Service(服务):Android应用程序的后台运行组件。

Service没有用户界面的程序。

服务组件在后台运行,它们可以更新数据源和可见的Activity,并触发Notification。

它们被用来执行一些需要在后台持续的常规处理。

例如媒体播放器这个activity会使用Context.startService()方法,连接到一个service上(如果这个service还没有运行将启动它)。

当连接到一个service之后,我们还可以通过service提供的接口与它进行通讯。

(3)Content Provider(内容提供器):用来管理和分享应用程序数据库。

Content Provider 是在应用程序之间共享数据的首选方法。

通过配置Content Provider允许其他应用程序访问存储的数据,也可以使用其他应用程序提供的Content Provider来访问它们存储的数据。

Android平台也提供了系统自带的Content Provider,如联系人信息等。

(4)Intent(意向):Activity之间的粘合剂。

使用Intent,可以在系统范围内向目标活动或者服务广播消息,说明希望执行某个动作的意图。

之后系统就会确定那些最适合执行动作的目标。

(5)Notification(通知):一种用户通知框架。

通过允许向用户发送信号,而不会过分吸引他们的注意力或者打断他们当前的活动。

它们是服务或者广播接收器吸引用户注意的首选方法。

例如,当设备接收到一个文本消息或者来电的时候,它可以通过闪灯、发出声音、显示图标或则会显示对话框信息的方式提示用户。

(6)Intent Receiver(意向接收器):通过Intent Receiver实现应用能够对一个外部的事件作出响应,Intent Receiver在AndroidManifest.xml中注册,但也可以在代码中使用Context.registerReceiver()进行注册。

当一个intent receive被触发时,应用不必对请求调用intent receive,系统会在需要的时候启动你的应用。

各种应用还可以通过使用Context.broadcastIntent()将它们自己的intent receive广播给其他应用程序。

3.2功能的具体实现(1)计算器布局设计:分别实用Button按钮操作17个按钮,分别是+、—、*、/、=、0-9、清除按钮,以及EditTest的文本域,并通过代码布局调整布局,使布局更加清晰,简洁。

布局方式如图所示:代码实现如下:<RelativeLayoutxmlns:android="/apk/res/android"xmlns:tools="/tools"android:layout_width="match_parent"android:layout_height="match_parent"android:paddingBottom="@dimen/activity_vertical_margin"android:paddingLeft="@dimen/activity_horizontal_margin"android:paddingRight="@dimen/activity_horizontal_margin"android:paddingTop="@dimen/activity_vertical_margin"tools:context=".MainActivity"><EditTextandroid:id="@+id/editText1"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_alignParentLeft="true"android:layout_alignParentRight="true"android:layout_alignParentTop="true"android:layout_marginTop="17dp"android:ems="10"/><Buttonandroid:id="@+id/button1"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_alignLeft="@+id/editText1"android:layout_below="@+id/editText1"android:layout_marginTop="30dp"android:text="1"/><Buttonandroid:id="@+id/button2"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_alignBaseline="@+id/button1"android:layout_alignBottom="@+id/button1"android:layout_toRightOf="@+id/button1"android:text="2"/><Buttonandroid:id="@+id/button3"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_alignBaseline="@+id/button2"android:layout_alignBottom="@+id/button2"android:layout_toRightOf="@+id/button2"android:text="3"/><Buttonandroid:id="@+id/button4"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_alignParentLeft="true"android:layout_below="@+id/button1"android:text="4"/><Buttonandroid:id="@+id/button5"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_alignBaseline="@+id/button4"android:layout_alignBottom="@+id/button4"android:layout_alignLeft="@+id/button2"android:text="5"/><Buttonandroid:id="@+id/button6"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_below="@+id/button3"android:layout_toRightOf="@+id/button5"android:text="6"/><Buttonandroid:id="@+id/button7"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_below="@+id/button4"android:layout_toLeftOf="@+id/button5"android:text="7"/><Buttonandroid:id="@+id/button8"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_alignBaseline="@+id/button7"android:layout_alignBottom="@+id/button7"android:layout_alignLeft="@+id/button5"android:text="8"/><Buttonandroid:id="@+id/button9"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_alignBaseline="@+id/button8"android:layout_alignBottom="@+id/button8"android:layout_toRightOf="@+id/button5"android:text="9"/><Buttonandroid:id="@+id/button10"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_alignLeft="@+id/button7"android:layout_below="@+id/button7"android:text="0"/><Buttonandroid:id="@+id/button11"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_below="@+id/button7"android:layout_toRightOf="@+id/button7"android:text="."/><Buttonandroid:id="@+id/button12"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_alignBaseline="@+id/button11"android:layout_alignBottom="@+id/button11"android:layout_alignLeft="@+id/button9"android:text="="/><Buttonandroid:id="@+id/button13"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_alignBottom="@+id/button3"android:layout_toRightOf="@+id/button3"android:text="+"/><Buttonandroid:id="@+id/button14"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_alignBaseline="@+id/button6"android:layout_alignBottom="@+id/button6"android:layout_toRightOf="@+id/button6"android:text="-"/><Buttonandroid:id="@+id/button15"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_above="@+id/button12"android:layout_alignLeft="@+id/button14"android:text="*"/><Buttonandroid:id="@+id/button16"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_below="@+id/button9"android:layout_toRightOf="@+id/button9"android:text="/"/><Buttonandroid:id="@+id/button17"android:layout_width="match_parent"android:layout_height="wrap_content"android:layout_alignRight="@+id/button16"android:layout_below="@+id/button11"android:text="清除" /></RelativeLayout>(2)计算功能实现加法实现:从editTest中获取数字赋值于num1,等待数字num2的输入。

相关文档
最新文档