Android平台计算器设计.docx

上传人:b****1 文档编号:23136703 上传时间:2023-05-08 格式:DOCX 页数:24 大小:210.89KB
下载 相关 举报
Android平台计算器设计.docx_第1页
第1页 / 共24页
Android平台计算器设计.docx_第2页
第2页 / 共24页
Android平台计算器设计.docx_第3页
第3页 / 共24页
Android平台计算器设计.docx_第4页
第4页 / 共24页
Android平台计算器设计.docx_第5页
第5页 / 共24页
点击查看更多>>
下载资源
资源描述

Android平台计算器设计.docx

《Android平台计算器设计.docx》由会员分享,可在线阅读,更多相关《Android平台计算器设计.docx(24页珍藏版)》请在冰豆网上搜索。

Android平台计算器设计.docx

Android平台计算器设计

基于Android平台计算器设计

设计实现一个成功的应用程序,不但要有使用的功能配置,也要有有好的用户界面,下面就是我对基于Android计算器的设计简要介绍。

 

1 系统的总体设计 

根据任务书,符合使用用户的实际要求,系统应实现以下功能:

计算器界面友好,方便使用,显示至少6位结果,具有基本的加、减、乘、除功能,能够判断用户输入运算数是否正确,支持小数运算,具有退格功能,能够删除最后一个输入,具有清除功能,即C,具有结果存储功能,能够显示存储器状态,支持触屏手机。

 

整个程序基于android技术开发,出总体模块外主要分为输入模块、显示模块以及计算模块(包括一些其她功能)这三大部分。

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

下面较为详细的做了说明。

 

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

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

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

 

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

 

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

 

2 程序流程和系统功能设计 

2.1 程序流程设计 

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

系统流程图如图所示:

 

2.2系统功能设计 

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

下面就让我们用图来表示:

以上就是系统的流程图,不过只是一个简单是示意流程图,不是整个程序的完整流程图,整个系统的流程图由于模块众多,整个列举不易于理解,故此就只采用简单流程图作为示例说明,反而更加的简单明了。

 

3基于Android平台系统具体设计 

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

用系统框图来表示即如图。

 

 

系统这三大模块都各自包含什么内容在下文的系统详细设计中会有进一步的说明,此处就暂且略过。

 

下面就来详细的说明一下系统的各个模块都是如何设计的。

 

3.1 总体模块详细设计 

总体模块需要完成的任务主要就是系统的程序启动类,需要负责整个系统的生命周期。

同时在还要在模块中完成菜单栏的所有功能,即退出程序,记忆数据,显示数据,清除记忆数据这四个功能。

 

总体模块的功能图如图:

 

 

3.2 输入模块详细设计 

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

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

 

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

 

输入模块的功能图如图:

 

 

3.3 显示模块详细设计 

作为手机计算器系统,显示部分也是必不可少的一部分。

没有显示部分就没有办法显示用户输入的数字是否正确,甚至不能显示计算出的结果,由此可见显示模块即包括输入的部分也包括输出的部分。

 

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

同时本模块还将提供调用和设置显示的具体方法。

 

显示模块的功能图如图:

 

 

3.4 计算模块详细设计 

系统要完成整个的计算器的计算功能,那么计算模块就是整个系统的重点模块。

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

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

 

系统想要能在屏幕上显示出计算器的样子要有整体的布局,在本模块中要完成布局的具体设计,使用户能够看到整个计算器的画面。

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

这部分主要是对输入进行的逻辑判断,基本会通过if else来实现逻辑判断。

计算模块的功能图如图:

4计算器系统效果如下:

5计算器系统实现代码如下:

xmlversion="1.0"encoding="utf-8"?

>

android="

   android:

layout_width="match_parent"

   android:

layout_height="match_parent"

   android:

orientation="vertical">

   

layout_width="fill_parent"

   android:

layout_height="wrap_content">

 

    android:

id="@+id/tvResult"

    android:

layout_width="fill_parent"

    android:

layout_height="wrap_content"

    android:

height="50dp"

    android:

text="@string/tvResult"

    />

layout_width="fill_parent"

   android:

layout_height="wrap_content">

   

       android:

id="@+id/btnBackspace"

       android:

layout_width="wrap_content"

       android:

layout_height="wrap_content"

       android:

width="150dp"

       android:

layout_marginLeft="10dp"

            android:

text="@string/btnbackspace"/>

     

       android:

id="@+id/btnCE"

       android:

layout_width="wrap_content"

       android:

layout_height="wrap_content"

        android:

width="150dp"

            android:

text="@string/btnCE"/>

layout_width="fill_parent"

   android:

layout_height="wrap_content">

     

       android:

id="@+id/btn7"

       android:

layout_width="wrap_content"

       android:

layout_height="wrap_content"

       android:

layout_marginLeft="10dp"

        android:

width="75dp"

            android:

text="@string/btn7"/>

        

       android:

id="@+id/btn8"

       android:

layout_width="wrap_content"

       android:

layout_height="wrap_content"

        android:

width="75dp"

            android:

text="@string/btn8"/>

              

       android:

id="@+id/btn9"

       android:

layout_width="wrap_content"

       android:

layout_height="wrap_content"

        android:

width="75dp"

            android:

text="@string/btn9"/>

                    

       android:

id="@+id/btnDiv"

       android:

layout_width="wrap_content"

       android:

layout_height="wrap_content"

        android:

width="75dp"

            android:

text="@string/btnDiv"/>

layout_width="fill_parent"

   android:

layout_height="wrap_content">

     

       android:

id="@+id/btn4"

       android:

layout_width="wrap_content"

       android:

layout_height="wrap_content"

       android:

layout_marginLeft="10dp"

        android:

width="75dp"

            android:

text="@string/btn4"/>

        

       android:

id="@+id/btn5"

       android:

layout_width="wrap_content"

       android:

layout_height="wrap_content"

        android:

width="75dp"

            android:

text="@string/btn5"/>

              

       android:

id="@+id/btn6"

       android:

layout_width="wrap_content"

       android:

layout_height="wrap_content"

        android:

width="75dp"

            android:

text="@string/btn6"/>

                    

       android:

id="@+id/btnMul"

       android:

layout_width="wrap_content"

       android:

layout_height="wrap_content"

        android:

width="75dp"

            android:

text="@string/btnMul"/>

layout_width="fill_parent"

   android:

layout_height="wrap_content">

     

       android:

id="@+id/btn1"

       android:

layout_width="wrap_content"

       android:

layout_height="wrap_content"

       android:

layout_marginLeft="10dp"

        android:

width="75dp"

            android:

text="@string/btn1"/>

        

       android:

id="@+id/btn2"

       android:

layout_width="wrap_content"

       android:

layout_height="wrap_content"

        android:

width="75dp"

            android:

text="@string/btn2"/>

              

       android:

id="@+id/btn3"

       android:

layout_width="wrap_content"

       android:

layout_height="wrap_content"

        android:

width="75dp"

            android:

text="@string/btn3"/>

                    

       android:

id="@+id/btnAdd"

       android:

layout_width="wrap_content"

       android:

layout_height="wrap_content"

        android:

width="75dp"

            android:

text="@string/btnAdd"/>

layout_width="fill_parent"

   android:

layout_height="wrap_content">

     

       android:

id="@+id/btn0"

       android:

layout_width="wrap_content"

       android:

layout_height="wrap_content"

       android:

layout_marginLeft="10dp"

        android:

width="75dp"

            android:

text="@string/btn0"/>

        

       android:

id="@+id/btnC"

       android:

layout_width="wrap_content"

       android:

layout_height="wrap_content"

        android:

width="75dp"

            android:

text="@string/btnC"/>

              

       android:

id="@+id/btnEqu"

       android:

layout_width="wrap_content"

       android:

layout_height="wrap_content"

        android:

width="75dp"

            android:

text="@string/btnEqu"/>

                    

       android:

id="@+id/btnSub"

       android:

layout_width="wrap_content"

       android:

layout_height="wrap_content"

        android:

width="75dp"

            android:

text="@string/btnSub"/>

packagecom.example.week2;

importandroid.os.Bundle;

importandroid.view.View;

importandroid.view.View.OnClickListener;

importandroid.widget.Button;

importandroid.widget.TextView;

importandroid.app.Activity;

publicclassMainActivityextendsActivity implementsOnClickListener{

   //声明一些控件

   Buttonbtn0=null;

   Buttonbtn1=null;

   Buttonbtn2=null;

   Buttonbtn3=null;

   Buttonbtn4=null;

   Buttonbtn5=null;

   Buttonbtn6=null;

   Buttonbtn7=null;

   Buttonbtn8=null;

   Buttonbtn9=null;

   ButtonbtnBackspace=null;

   ButtonbtnCE=null;

   ButtonbtnC=null;

   ButtonbtnAdd=null;

   ButtonbtnSub=null;

   ButtonbtnMul=null;

   ButtonbtnDiv=null;

   ButtonbtnEqu=null;

   TextViewtvResult=null;

   //声明两个参数。

接收tvResult前后的值

   doublenum1=0,num2=0;

   doubleResult=0;//计算结果

   intop=0;//判断操作数,

   booleanisClickEqu=false;//判断是否按了“=”按钮

   @Override

   protectedvoidonCreate(BundlesavedInstanceState){

       super.onCreate(savedInstanceState);

       setContentView(R.layout.main);

       //从布局文件中获取控件,

       btn0=(Button)findViewById(R.id.btn0);

       btn1=(Button)findViewById(R.id.btn1);

       btn2=(Button)findViewById(R.id.btn2);

       btn3=(Button)findViewById(R.id.btn3);

       btn4=(Button)findViewById(R.id.btn4);

       btn5=(Button)findViewById(R.id.btn5);

       btn6=(Button)findViewById(R.id.btn6);

       btn7=(Button)findViewById(R.id.btn7);

       btn8=(Button)findViewById(R.id.btn8);

       btn9=(Button)findViewById(R.id.btn9);

       btnBackspace=(Button)findViewById(R.id.btnBackspace);

       btnCE=(Button)findViewById(R.id.btnCE);

       btnC=(Button)findViewById(R.id.btnC);

       btnEqu=(Button)findViewById(R.id.btnEqu);

       btnAdd=(Button)findViewById(R.id.btnAdd);

       btnSub=(Button)findViewById(R.id.btnSub);

       btnMul=(Button)findViewById(R.id.btnMul);

       btnDiv=(Button)findViewById(R.id.btnDiv);

       tvResult=(TextView)findViewById(R.id.tvResult);

       //添加监听\

       btnBackspace.setOnClickListener(this);

       btnCE.setOnClickListener(this);

       btn0.setOnClickListener(this);

       btn1.setOnClickListener(this);

       btn2.setOnClickListener(this);

       btn3.setOnClickListener(this);

       btn4.setOnClickListener(this);

       btn5.setOnClickListener(this);

       btn6.setOnClickListener(this);

       btn7.setOnClickListener(this);

       btn8.setOnClickListener(this);

       btn9.setOnCl

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 初中教育 > 英语

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1