计算器安卓设计

发布时间:2017-09-25 22:39:15

课程设计报告

ANDROID开发

简单计算器

计算机工程学院

计算机科学与技术

15计算机科学与技术

周江成

1513902035

课程设计地点 1416

课程设计学时

叶崧

金陵科技学院教务处制


课程设计报告书写要求

课程设计报告原则上要求学生手写,要求书写工整。若因课程特点需打印的,要遵照以下字体、字号、间距等的具体要求。纸张一律采用A4的纸张。

课程设计报告书写说明

课程设计报告应包含以下七部分内容:1、摘要  2、目录  3、前言/引言  4.正文 5. 结论   6. 参考文献    7. 附录,每部分的书写要求参见具体条目要求。

填写注意事项

1)准确说明,层次清晰。

2)尽量采用专用术语来说明事物。 

3)外文、符号、公式要准确,应使用统一规定的名词和符号。

4)应独立完成课程设计报告的书写,严禁抄袭、复印,一经发现,以零分论处

课程设计报告批改说明

课程设计报告的批改要及时、认真、仔细,一律用红色笔批改。课程设计报告的批改成绩采用五级计分制或百分制,具体评分标准由各院部自行制定。

课程设计报告装订要求

报告批改完毕后,任课老师应将课程设计报告以自然班为单位、按学号升序排列,并附上一份该课程设计的教学大纲。


课程设计题目:

简单计算器

1、摘要(所进行设计工作的主旨、缘起、 目的,设计工作的主要内容、过程,采用的方法及取得的成果。关键字(Key Words): 一般35个,最能代表报告内容特征,或在报告起关键作用,最能说明问题的词组)

目前手机可以说是普及率非常高的电子设备了,由于其便于携带,使用方便,资费适中等等原因,现在手机已经在一定程度开始代替固定电话的通话功能,以及一些原来电脑软件上的功能了。手机上的软件也随着手机的发展变得丰富起来了,时至今日已经出现了很多专门制作手机软件的公司,虽然制作的多是游戏软件,但是一些辅助性的工具软件也有了很多.我在此次系统中所做的工作主要是设计整个系统以及利用编程语言实现整个系统,使系统能够正确的运行计算功能。

本程序是一个基于现有手机计算器开发的在触屏手机上运行的简单计算器,使用户可以更加简单便捷的使用计算器功能,在此次程序设计中所做的工作主要是设计程序的图形化操作界面,以及利用编程语言实现整个程序的计算功能,使其能够正确运行。

设计的计算器应用程序可以完成加法、减法、乘法以及除法,并且具有删除和清空的功能。

关键词:Android、应用开发、计算器


二、目录

一.前言

二.正文

1.开发环境

2.程序流程设计

3.系统功能设计

4.基于Android平台系统具体设计

5.总体模块详细设计

6.输入模块详细设计

7.显示模块详细设计

8.计算模块详细设计

9.界面设计截图

三.总结

四.参考文献

五.附录


三、前言(说明本次课程设计课题意义,本课题相关技术特点,拟采用的方案或路线)

通过此次课程设计,巩固所学Java语言的基础知识,增进Java语言编辑基本功,掌握JDKAndroid Studio等开发工具的应用,拓展常用类库的应用。使学生通过该教学环节与手段,把所学课程及相关知识加以融汇贯通,全面掌握Java语言的编程思想及面向对象程序设计的方法。

根据用户的实际要求,程序应实现以下功能:计算器界面友好,方便使用,具有基本的加、减、乘、除功能,能够判断用户输入运算数是否正确,支持小数点运算,具有退格功能,能够删除最后一个输入,具有清除功能。

整个程序基于Android技术开发,除总体模块外主要分为输入模块、显示模块以及计算模块这三大部分。在整个系统中总体模块控制系统的生命周期,输入模块部分负责读取用户输入的数据,显示模块部分负责显示用户之前输入的数据以及显示最终的计算结果,计算机模块负责进行数据的运算以及一些其他的功能。

具体的说,总体模块的作用主要是生成应用程序的主类,控制应用程序的生命周期。输入模块只要描述了计算器键盘以及键盘的监听即主要负责读取用户的键盘输入以及响应触屏的按键,需要监听手机动作以及指针事件处理触屏的单击操作,同时提供了较为直观的键盘图形用户界面。显示模块描述了计算器的显示区,即该区域用于显示用户输入的数据以及最终的计算结果,同时负责显示一些其他的信息。

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

系统除了总体模块以外主要由三大模块来组成,即输入模块、显示模块和计算模块,如下图所示:

三大模块

输入模块主要描述了计算器键盘以及键盘的监听即负责读取用户的键盘输入以及响应触屏的按键,需要监听手机按键的动作以及指针事件处理方法处理触屏的单击操作(以松开按键为标准)。同时提供了较为直观的键盘图形用户界面。显示模块描述了计算器的显示区,即该区域用于显示用户输入的数据以及最终的计算结果,同时负责显示一些其他的信息。计算模块则主要描述了计算器的整体,实现了计算器的界面,负责计算用户输入的数据,包括加、减、乘、除等各种功能,退格以及清零的功能。

4、正文包含所进行设计的整体内容)

1、开发环境

AndroidGoogle2007115日宣布基于Linux平台的开源手机操作系统的名称,该平台由操作系统、中间件、用户界面和应用软件组成,号称是首个移动端打造的真正开放和完整的移动软件。可以把它理解成Linux上套了一个JAVA的壳。

Android的平台基本上是免费的,虽然有部分原生链接库会要求费用,但大部分是免权利金的。Android的程序可以采用JAVA开发,因为它的虚拟机Dalvik,只是它将JAVAbytecode转成自己的格式,回避掉需要付给SUN有关JAVA的授权费用,因此,Android开发环境是需要JDK的。

Android Studio 是一个Android集成开发工具,基于IntelliJ IDEA. 类似 Eclipse ADTAndroid Studio 提供了集成的 Android 开发工具用于开发和调试。

2、程序流程设计

知道了系统的功能以后,我们通过main.xml来建立显示界面,完成后系统开始监听用户的按键输入,每次输入系统都会判断一次用户输入的类型,是数字还是运算符号或者是清除,判断完后分成不同类型如数字,符号,基本运算等等进行进一步的处理,根据用户的要求继续进行下一步的操作,最后计算出最终结果并显示在显示区。

流程设计图如下所示:

3、系统功能设计

整个系统的功能比较多,比较复杂,如上所说,可以分为十多个功能模块,但是逻辑上理解其实不算难,系统包括如普通计算功能,包括加减乘除,退格以及清零功能。

4、基于Android平台系统具体设计

系统除了总体模块以外主要由三大模块来组成,即输入模块,显示模块和计算模块。用系统框图来显示。即如下图:

5、总体模块详细设计

总体模块需要完成的任务主要就是系统的程序启动类,需要负责整个系统的生命周期。同时还要在模块中完成菜单栏上的所有功能,退出程序,记忆数据,显示数据,清除记忆数据这四个功能

如下:

6、输入模块详细设计

系统如果想要完成计算器中的各种功能,首先用户要能进行数据输入,由于是在触屏手机上开发计算器程序,所以要求输入可以直接使用触屏进行,所以在设计的时候就要充分考虑这一点。所以在进行模块设计师,选择编写输入模块类的时候会选取使用了可以支持触屏输入的特殊增强行的图形用户界面类。

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

如下:

7、显示模块详细设计

显示模块主要完成的任务是描述计算器的显示区,该区域用于显示用户输入的数据以及最终的计算结果和一些其他信息。同时本模块还将提供和设置显示的具体方法。

如图:

8、计算模块详细设计

系统想要能在屏幕上显示出计算器的样子要有整体的布局,在本模块中要完成布局的具体设计,使用户能够看到整个计算器的界面。同时系统想要完成计算功能必须要处理用户的输入,当输入模块的监听传到计算模块中,计算模块就要根据相应的方法进行进一步逻辑判断。

如下:

9、界面设计截图


五、结论  (对整个设计工作的总结,可以包括作者提出的建议、下一步工作的设想及改进意见等)

课程设计终于在我的努力下做完了。这个时候我更加深入的了解了Java的特点以及一些相关知识。 与其临渊羡鱼,不如退而结网。这次Android课程设计给我的最大的印象就是如果自己有了兴趣,就动手去做,困难在你的勇气和毅力下是抬不了头的。如果你连失败都不怕了,那你还怕什么,拾起懒惰的心,勤奋着就会走向成功斩。这次的课程设计在我未来的时日里,是一个标杆,因为它告诉了我,只要我努力没有什么事我做不好的。安卓开发是个很有意思的事情,以后可以在自己手机上安装自己开发的一些小程序,也是个非常不错的事情,目前还没有个安卓机子,而在其他同学手机测试过后,还是比较不错的

六、参考文献(撰写论文过程中所参考的文章、书本及其它文献。)

[1] 王小科,Android入门经典[M],北京:机械工业出版社,2013.

[2] DevDiv移动开发社区,Android开发实战体验[M],北京:海洋出版社,2013

[3] 第一行代码

[4] 2015最新Android基础入门教程

7、附录(相关图纸及源程序等)

目录结构

Activity_main.xml中的源代码

xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
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="com.example.work.MainActivity">

<EditText
android:layout_width="fill_parent"
android:layout_height="80dip"
android:id="@+id/et_input"
android:editable="false"
android:gravity="right|bottom"
/>

<LinearLayout
android:layout_marginTop="10dp"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal"
android:layout_below="@+id/et_input"
android:layout_alignParentStart="true"
android:weightSum="1">

<Button
android:layout_width="60dp"
android:layout_height="74dp"
android:text="清空"
android:textSize="20sp"

android:id="@+id/btn_clear"
android:layout_weight="0.54" />

<Button
android:layout_width="60dp"

android:layout_height="74dp"
android:text="删除"
android:textSize="20sp"
android:id="@+id/btn_del"
android:layout_weight="0.46" />
<Button
android:layout_width="59dp"

android:layout_height="74dp"
android:text="/"
android:textSize="20sp"
android:id="@+id/btn_divide"
/>

<Button
android:layout_width="59dp"
android:layout_height="74dp"
android:text="*"

android:textSize="20sp"
android:id="@+id/btn_multiply"
/>

LinearLayout>
//第二行开始*******************************
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_marginTop="80dp"
android:orientation="horizontal"
android:layout_below="@+id/et_input"
android:layout_alignParentStart="true"
android:weightSum="1">

<Button
android:layout_width="60dp"
android:layout_height="74dp"
android:text="7"

android:textSize="20sp"
android:id="@+id/btn_7"
android:layout_weight="0.54" />

<Button
android:layout_width="60dp"
android:layout_height="74dp"
android:text="8"
android:textSize="20sp"

android:id="@+id/btn_8"
android:layout_weight="0.46" />

<Button
android:layout_width="59dp"
android:layout_height="74dp"
android:text="9"

android:textSize="20sp"
android:id="@+id/btn_9"
/>

<Button
android:layout_width="59dp"
android:layout_height="74dp"
android:text="-"

android:textSize="20sp"
android:id="@+id/btn_minus"
/>

LinearLayout>
//第三行开始********************************
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_marginTop="150dp"
android:orientation="horizontal"
android:layout_below="@+id/et_input"
android:layout_alignParentStart="true"
android:weightSum="1">

<Button
android:layout_width="60dp"
android:layout_height="74dp"
android:text="4"

android:textSize="20sp"
android:id="@+id/btn_4"
android:layout_weight="0.54" />

<Button
android:layout_width="60dp"
android:layout_height="74dp"
android:text="5"

android:textSize="20sp"
android:id="@+id/btn_5"
android:layout_weight="0.46" />
<Button
android:layout_width="59dp"
android:layout_height="74dp"
android:text="6"

android:textSize="20sp"
android:id="@+id/btn_6"
/>

<Button
android:layout_width="59dp"
android:layout_height="74dp"
android:text="+"

android:textSize="20sp"
android:id="@+id/btn_plus"
/>

LinearLayout>
//第四行***************************************************************
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_marginTop="220dp"
android:orientation="horizontal"
android:layout_below="@+id/et_input"
android:layout_alignParentStart="true"
android:weightSum="1">

<Button
android:layout_width="60dp"
android:layout_height="74dp"
android:text="1"

android:textSize="20sp"
android:id="@+id/btn_1"
android:layout_weight="0.54" />

<Button
android:layout_width="60dp"
android:layout_height="74dp"
android:text="2"

android:textSize="20sp"
android:id="@+id/btn_2"
android:layout_weight="0.46" />
<Button
android:layout_width="59dp"
android:layout_height="74dp"
android:text="3"

android:textSize="20sp"
android:id="@+id/btn_3"
/>

<Button
android:layout_width="59dp"
android:layout_height="74dp"
android:text="0"

android:textSize="20sp"
android:id="@+id/btn_0"
/>
LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_marginTop="290dp"
android:orientation="horizontal"
android:layout_below="@+id/et_input"
android:layout_alignParentStart="true"
android:weightSum="1">

<Button
android:layout_width="95dp"
android:layout_height="74dp"
android:text="."

android:textSize="20sp"
android:id="@+id/btn_point"
android:layout_weight="0.71" />

<Button
android:layout_width="223dp"
android:layout_height="74dp"
android:text="="

android:textSize="20sp"
android:id="@+id/btn_equal"
android:layout_weight="0.24" />
LinearLayout>

RelativeLayout>

MainActivity.java中的源代码

package com.example.work;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {
Button btn_0 ;
Button btn_1;
Button btn_2;
Button btn_3 ;
Button btn_4 ;
Button btn_5 ;
Button btn_6 ; //数字按钮
Button btn_7 ;
Button btn_8 ;
Button btn_9 ;
Button btn_point ; //小数点按钮
Button btn_clear ;
Button btn_del ;
Button btn_pluse ;
Button btn_minus ;
Button btn_multiply ;
Button btn_divide ;
Button btn_equle ;
EditText et_input ;
boolean clear_flag ;//清空标识

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btn_0 = (Button) findViewById(R.id.btn_0) ;
btn_1 = (Button) findViewById(R.id.btn_1) ;
btn_2 = (Button) findViewById(R.id.btn_2) ;
btn_3 = (Button) findViewById(R.id.btn_3) ;
btn_4 = (Button) findViewById(R.id.btn_4) ;
btn_5 = (Button) findViewById(R.id.btn_5) ;
btn_6 = (Button) findViewById(R.id.btn_6) ;
btn_7 = (Button) findViewById(R.id.btn_7) ;
btn_8 = (Button) findViewById(R.id.btn_8) ;
btn_9 = (Button) findViewById(R.id.btn_9) ;
btn_point = (Button) findViewById(R.id.btn_point) ;
btn_clear = (Button) findViewById(R.id.btn_clear) ;
btn_del = (Button) findViewById(R.id.btn_del) ;
btn_pluse = (Button) findViewById(R.id.btn_plus) ;
btn_minus = (Button) findViewById(R.id.btn_minus) ;
btn_multiply = (Button) findViewById(R.id.btn_multiply) ;
btn_divide = (Button) findViewById(R.id.btn_divide) ;
btn_equle = (Button) findViewById(R.id.btn_equal) ;
//以上实例化按钮
et_input = (EditText) findViewById(R.id.et_input); //实例化之后的显示屏

btn_0.setOnClickListener(this);
btn_1.setOnClickListener(this);
btn_2.setOnClickListener(this);
btn_3.setOnClickListener(this);
btn_4.setOnClickListener(this);
btn_5.setOnClickListener(this);
btn_6.setOnClickListener(this);
btn_7.setOnClickListener(this);
btn_8.setOnClickListener(this);
btn_9.setOnClickListener(this);
btn_point.setOnClickListener(this);
btn_clear.setOnClickListener(this);
btn_del.setOnClickListener(this);
btn_pluse.setOnClickListener(this);
btn_minus.setOnClickListener(this);
btn_multiply.setOnClickListener(this);
btn_divide.setOnClickListener(this);
btn_equle.setOnClickListener(this);
//设置以上按钮的点击事件


}

@Override
public void onClick(View v) {
String str = et_input.getText().toString();
switch (v.getId()) {
case R.id.btn_0:
case R.id.btn_1:
case R.id.btn_2:
case R.id.btn_3:
case R.id.btn_4:
case R.id.btn_5:
case R.id.btn_6:
case R.id.btn_7:
case R.id.btn_8:
case R.id.btn_9:
case R.id.btn_point:
if (clear_flag) {
clear_flag =false ;
str ="" ;
et_input.setText("");
}
et_input.setText(str + ((Button)v).getText());
break ;
case R.id.btn_plus:
case R.id.btn_minus:
case R.id.btn_multiply:
case R.id.btn_divide:
if (clear_flag) {
clear_flag =false ;
str ="" ;
et_input.setText("");
}
et_input.setText(str+ " " + ((Button)v).getText()+" ");
break;
case R.id.btn_del:
if (clear_flag) {
clear_flag =false ;
str ="" ;
et_input.setText("");
}else if (str!=null&&!str.equals("")){
et_input.setText(str.substring(0,str.length()-1));
}
break;
case R.id.btn_clear:
clear_flag =false ;
str ="" ;
et_input.setText("");
case R.id.btn_equal:
getResult();
break ;

}
}
/* 单独的调用运算结果
*
*
* */
private void getResult(){
String exp = et_input.getText().toString();
if (exp == null||exp.equals("")){
return;
}
if(!exp.contains(" ")) {
return;
}
if (clear_flag){
clear_flag = false ;
return;

}
clear_flag = true ;
double result = 0 ;
String s1 = exp.substring(0,exp.indexOf(" ")); //运算符前面的字符串
String op = exp.substring(exp.indexOf(" ")+1,exp.indexOf(" ")+2) ;
String s2 = exp.substring(exp.indexOf(" ")+3) ;
if (!s1.equals(" ")&&!s2.equals(" ")){
double d1 = Double.parseDouble(s1) ;
double d2 = Double.parseDouble(s2) ;
if (op.equals("+")){
result = d1 + d2 ;

}else if (op.equals("-")){
result = d1 - d2 ;

}else if (op.equals("*")){
result = d1 * d2 ;

}else if (op.equals("/")){
if(d2 == 0){
result = 0 ;
}else {
result = d1/d2 ;
}
}
if (s1.contains(".")&&s2.contains(".")) {
int r = (int) result;
et_input.setText(r+"");
}else {
et_input.setText(result+"");

}
}else if (!s1.equals("")&&s2.equals("")){
et_input.setText(exp);
}else if (s1.equals("")&&!s2.equals("")){
double d2 = Double.parseDouble(s2) ;
if (op.equals("+")){
result = 0 + d2 ;

}else if (op.equals("-")){
result = 0 - d2 ;

}else if (op.equals("*")){
result = 0 ;

}else if (op.equals("/")){
result = 0 ;
}
if (s2.contains(".")) {
int r = (int) result;
et_input.setText(r+"");
}else {
et_input.setText(result+"");
}
}else {
et_input.setText("");

}
}
}

AndroidMainfest.xml中的相关设置,代码如下:

xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.work">

<application

android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action

android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
intent-filter>
activity>
application>

manifest>

计算器安卓设计

相关推荐