天天看點

【軟體工程Ⅱ】作業五 |結對項目-國小四則運算 “軟體”之更新版

本次作業的要求來自于:https://edu.cnblogs.com/campus/gzcc/GZCC-16SE2/homework/2232

本次作業代碼的github位址:https://github.com/Hongnnn/ruanjiangongcheng.git

一、前言

本次作業為結對項目,要求兩個人一組完成國小四則運算 “軟體”之更新版,本次結對同伴的學号:201608030062,姓名:黃宏娜,同伴的部落格位址為:http://www.cnblogs.com/hongna/p/9869892.html

二、開發環境:Android Studio

首先,我們是用Android Stuodio做的國小四則運算 app,本次項目代碼已經送出到github的da檔案,可運作 apk位于pubulic檔案夾下。

三、App功能

從個人項目出發,将程式改裝成一個單機帶使用者界面(不是控制台)的程式,這個程式最基本要達到:

  • 生成題目,單個題目最多不能超過4個運算符,操作數小于100。
  • 使用者可以輸入答案
  • 若使用者輸入答案正确,則提示正确;若答案錯誤,則提示錯誤,并要提示正确答案是多少。

下面附有 8 個互相獨立的可以擴充的方向,橙色字型的為選取的擴充方向并加以實作的功能。

  1. 程式可以出帶括号的正整數四則運算,支援分數,除法保留兩位小數,如:(1/3+1)*2 = 2.67,特别注意:這裡是2.67而非2.66
  2. 可以出表達式裡含有負整數(負整數最小不小于-100)的題目,且負數需要帶括号,使用者輸入的結果不用帶括号。如: 2*(-4) = -8
  3. 使用者答題結束以後,程式可以顯示使用者答題所用的時間
  4. 使用者可以選擇出題的個數(最多不能超過5個題目),答題結束可以顯示使用者答錯的題目個數和答對的題目個數
  5. 使用者在第一次答題時,需要使用者輸入使用者名,使用者下次啟動後,程式需要記住使用者前一次輸入的使用者名 
  6. 程式可以出單個整數階乘的題目:如:4!=24
  7. 程式可以設定答題時間,時間設定為整數,機關為秒,最大不能超過120秒,若超過了答題時間未答題,則提示:時間已到,不能答題。
  8. 程式可以設定皮膚功能,可以改變界面的顔色即可。

四、國小四則運算 “軟體”之更新版實作

1.需求分析

【軟體工程Ⅱ】作業五 |結對項目-國小四則運算 “軟體”之更新版

2.功能實作

我主要實作的是登入、注冊以及整數階乘的題目,其餘功能實作在我同伴的部落格随筆中,同伴的位址在前言中已給出。

(1)登入功能

使用者可以在此界面輸入使用者名和密碼登入進入國小四則運算中,在此界面,若使用者輸入的使用者名或密碼為空,則提示使用者輸入使用者名和密碼;若使用者輸入的使用者名和密碼正确,則進入到國小四則運算app是首頁中;若輸入的使用者名不存在,則提示使用者輸入的使用者名不存在。其實作代碼如下所示:

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/screen"
    android:background="@mipmap/one"
    android:orientation="vertical"
    tools:context="com.hhn.asus.da.MainActivity">
    <TextView
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:text="登入界面"
        android:gravity="center"
        android:textSize="30sp"
        />


    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="@dimen/item_height_normal"
        android:layout_marginLeft="@dimen/margin_large"
        android:layout_marginRight="@dimen/margin_large"
        android:layout_marginTop="@dimen/dp_120">

        <ImageView
            android:id="@+id/img_account"
            android:layout_width="@dimen/dp_19"
            android:layout_height="@dimen/dp_20"
            android:layout_alignParentBottom="true"
            android:layout_marginBottom="@dimen/margin_tiny"
            android:layout_marginLeft="@dimen/margin_tiny"
            android:scaleType="fitXY"
            android:src="@mipmap/icon_login_account"/>

        <EditText
            android:id="@+id/et_account"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_gravity="center"
            android:layout_marginBottom="@dimen/margin_tiny"
            android:layout_marginLeft="@dimen/margin_normal"
            android:layout_toRightOf="@+id/img_account"
            android:background="@null"
            android:hint="@string/account"
            android:maxLines="1"
            android:textColor="@android:color/black"
            android:textColorHint="@color/tv_gray_deep"
            android:textSize="@dimen/text_size_normal"/>

        <View
            android:layout_width="match_parent"
            android:layout_height="@dimen/line_height"
            android:layout_alignParentBottom="true"
            android:layout_marginLeft="@dimen/margin_normal"
            android:layout_toRightOf="@+id/img_account"
            android:background="@color/orange_light"/>
    </RelativeLayout>

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="@dimen/item_height_normal"
        android:layout_marginLeft="@dimen/margin_large"
        android:layout_marginRight="@dimen/margin_large">

        <ImageView
            android:id="@+id/img_pw"
            android:layout_width="@dimen/dp_18"
            android:layout_height="@dimen/dp_20"
            android:layout_alignParentBottom="true"
            android:layout_marginBottom="@dimen/margin_tiny"
            android:layout_marginLeft="@dimen/margin_tiny"
            android:scaleType="fitXY"
            android:src="@drawable/icon_login_pw"/>

        <EditText
            android:id="@+id/et_password"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_gravity="center"
            android:layout_marginBottom="@dimen/margin_tiny"
            android:layout_marginLeft="@dimen/margin_normal"
            android:layout_toRightOf="@+id/img_pw"
            android:background="@null"
            android:hint="@string/password"
            android:inputType="textPassword"
            android:maxLines="1"
            android:textColor="@android:color/black"
            android:textColorHint="@color/tv_gray_deep"
            android:textSize="@dimen/text_size_normal"/>
        <ImageView
            android:id="@+id/iv_see_password"
            android:layout_width="@dimen/image_height_litter"
            android:layout_height="@dimen/image_height_litter"
            android:src="@drawable/image_password_bg"
            android:layout_centerVertical="true"
            android:layout_alignParentRight="true"
            android:scaleType="fitXY"
            />
        <View
            android:layout_width="match_parent"
            android:layout_height="@dimen/line_height"
            android:layout_alignParentBottom="true"
            android:layout_marginLeft="@dimen/margin_normal"
            android:layout_toRightOf="@+id/img_pw"
            android:background="@color/orange_light"/>
    </RelativeLayout>


    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="center"
        android:orientation="horizontal">

        <Button
            android:id="@+id/btn_login"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginLeft="60dp"
            android:layout_marginRight="60dp"
            android:layout_marginTop="@dimen/dp_15"
            android:layout_weight="1"
            android:background="@drawable/btn_orange_selector"
            android:paddingBottom="@dimen/margin_small"
            android:paddingTop="@dimen/margin_small"
            android:text="@string/login"
            android:textColor="@android:color/background_light"
            android:textSize="@dimen/text_size_normal" />

        <Button
            android:id="@+id/btn_zhu"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginLeft="45dp"
            android:layout_marginRight="45dp"
            android:layout_marginTop="15dp"
            android:layout_weight="1"
            android:background="@drawable/btn_orange_selector"
            android:paddingBottom="4dp"
            android:paddingTop="4dp"
            android:text="@string/zhu"
            android:textColor="@android:color/white"
            android:textSize="@dimen/text_size_normal" />
    </LinearLayout>
</LinearLayout>      

MainActivity.java

package com.hhn.asus.da;


import android.app.Activity;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.InputType;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.Toast;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ThreadPoolExecutor;


import db.Sqlite;
import db.User;
class PublicWay {

    public static List<Activity> activityList = new ArrayList<Activity>();
}
public class MainActivity extends AppCompatActivity {

    private Button reg;
    private Button login;
    private EditText count;
    private EditText pwd;
    private ImageView  seepassword;

    private List<User> userList;
    private List<User> dataList = new ArrayList<>();
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        PublicWay.activityList.add(this);

        reg= (Button) findViewById(R.id.btn_zhu);
        login= (Button) findViewById(R.id.btn_login);
        count= (EditText) findViewById(R.id.et_account);
        pwd= (EditText) findViewById(R.id.et_password);
        seepassword=(ImageView)findViewById(R.id.iv_see_password);
        seepassword.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                setPasswordVisibility();
            }
        });



        reg.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(MainActivity.this,RegisterActivity.class);
                startActivityForResult(intent,1);

            }
        });
        login.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String name=count.getText().toString().trim();
                String pass=pwd.getText().toString().trim();
                //userList=SqliteDB.getInstance(getApplicationContext()).loadUser();
                int result=Sqlite.getInstance(getApplicationContext()).Quer(pass,name);
                if (result==1)
                {

                    Toast.makeText(MainActivity.this,"登入成功",Toast.LENGTH_LONG).show();
                    Intent intent=new Intent();
                    intent.setClass(MainActivity.this,one.class);
                    startActivity(intent);


                }
                else if (result==0){
                    Toast.makeText(MainActivity.this,"使用者名不存在",Toast.LENGTH_LONG).show();


                }
                else if(result==-1)
                {
                    Toast.makeText(MainActivity.this,"密碼錯誤",Toast.LENGTH_LONG).show();

                }
/*                for (User user : userList) {

                    if (user.getUsername().equals(name))
                    {
                        if (user.getUserpwd().equals(pass))
                        {
                            state.setText("登入成功!");

                        }else {
                            state.setText("密碼錯誤!");

                        }
                    }
                    else {
                        state.setText("使用者名不存在!");

                    }

                }*/


            }
        });}
    private void setPasswordVisibility() {
        if(seepassword.isSelected()){
            seepassword.setSelected(false);
           pwd.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);

        }
        else {
            seepassword.setSelected(true);
          pwd.setInputType(InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD);
        }
    }

    @Override
    protected void onActivityResult(int requestCode,int resultCode,Intent data){
        super.onActivityResult(requestCode,resultCode,data);
        if(data!=null){
            String username=data.getStringExtra("name");
            if(!TextUtils.isEmpty(username)){
                count.setText(username);
                count.setSelection(username.length());
            }
        }
    }

}      

頁面運作結果如下所示:

【軟體工程Ⅱ】作業五 |結對項目-國小四則運算 “軟體”之更新版

(2)注冊功能

使用者可以在此界面輸入使用者名和密碼進行注冊,在此界面,若使用者輸入的使用者名或密碼為空,則提示使用者輸入使用者名和密碼;若使用者輸入的使用者名和密碼格式正确,則注冊成功;若輸入的使用者名已存在,則提示使用者輸入的使用者名已存在。其實作代碼如下所示:

register_activity.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/screen"
    android:background="@mipmap/one"
    android:orientation="vertical"
    tools:context="com.hhn.asus.da.MainActivity">
    <TextView
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:text="注冊界面"
        android:gravity="center"
        android:textSize="30sp"
        />


    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="@dimen/item_height_normal"
        android:layout_marginLeft="@dimen/margin_large"
        android:layout_marginRight="@dimen/margin_large"
        android:layout_marginTop="@dimen/dp_120">

        <ImageView
            android:id="@+id/img_account"
            android:layout_width="@dimen/dp_19"
            android:layout_height="@dimen/dp_20"
            android:layout_alignParentBottom="true"
            android:layout_marginBottom="@dimen/margin_tiny"
            android:layout_marginLeft="@dimen/margin_tiny"
            android:scaleType="fitXY"
            android:src="@mipmap/icon_login_account"/>

        <EditText
            android:id="@+id/et_account"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_gravity="center"
            android:layout_marginBottom="@dimen/margin_tiny"
            android:layout_marginLeft="@dimen/margin_normal"
            android:layout_toRightOf="@+id/img_account"
            android:background="@null"
            android:hint="@string/account"
            android:maxLines="1"
            android:textColor="@android:color/black"
            android:textColorHint="@color/tv_gray_deep"
            android:textSize="@dimen/text_size_normal"/>

        <View
            android:layout_width="match_parent"
            android:layout_height="@dimen/line_height"
            android:layout_alignParentBottom="true"
            android:layout_marginLeft="@dimen/margin_normal"
            android:layout_toRightOf="@+id/img_account"
            android:background="@color/orange_light"/>
    </RelativeLayout>

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="@dimen/item_height_normal"
        android:layout_marginLeft="@dimen/margin_large"
        android:layout_marginRight="@dimen/margin_large">

        <ImageView
            android:id="@+id/img_pw"
            android:layout_width="@dimen/dp_18"
            android:layout_height="@dimen/dp_20"
            android:layout_alignParentBottom="true"
            android:layout_marginBottom="@dimen/margin_tiny"
            android:layout_marginLeft="@dimen/margin_tiny"
            android:scaleType="fitXY"
            android:src="@drawable/icon_login_pw"/>

        <EditText
            android:id="@+id/et_password"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_gravity="center"
            android:layout_marginBottom="@dimen/margin_tiny"
            android:layout_marginLeft="@dimen/margin_normal"
            android:layout_toRightOf="@+id/img_pw"
            android:background="@null"
            android:hint="@string/password"
            android:inputType="textPassword"
            android:maxLines="1"
            android:textColor="@android:color/black"
            android:textColorHint="@color/tv_gray_deep"
            android:textSize="@dimen/text_size_normal"/>
        <View
            android:layout_width="match_parent"
            android:layout_height="@dimen/line_height"
            android:layout_alignParentBottom="true"
            android:layout_marginLeft="@dimen/margin_normal"
            android:layout_toRightOf="@+id/img_pw"
            android:background="@color/orange_light"/>
    </RelativeLayout>

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="@dimen/item_height_normal"
        android:layout_marginLeft="@dimen/margin_large"
        android:layout_marginRight="@dimen/margin_large">

        <ImageView
            android:id="@+id/img_pw_again"
            android:layout_width="@dimen/dp_18"
            android:layout_height="@dimen/dp_20"
            android:layout_alignParentBottom="true"
            android:layout_marginBottom="@dimen/margin_tiny"
            android:layout_marginLeft="@dimen/margin_tiny"
            android:scaleType="fitXY"
            android:src="@drawable/icon_login_pw"/>

        <EditText
            android:id="@+id/et_password_again"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_gravity="center"
            android:layout_marginBottom="@dimen/margin_tiny"
            android:layout_marginLeft="@dimen/margin_normal"
            android:layout_toRightOf="@+id/img_pw_again"
            android:background="@null"
            android:hint="請再次輸入登入密碼"
            android:inputType="textPassword"
            android:maxLines="1"
            android:textColor="@android:color/black"
            android:textColorHint="@color/tv_gray_deep"
            android:textSize="@dimen/text_size_normal" />
        <View
            android:layout_width="match_parent"
            android:layout_height="@dimen/line_height"
            android:layout_alignParentBottom="true"
            android:layout_marginLeft="@dimen/margin_normal"
            android:layout_toRightOf="@+id/img_pw_again"
            android:background="@color/orange_light"/>
    </RelativeLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="67dp"
        android:layout_gravity="center"
        android:layout_marginTop="15dp"
        android:gravity="center_vertical|center"
        android:orientation="horizontal"
        android:weightSum="1">

        <Button
            android:id="@+id/btn_register"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/btn_orange_selector"
            android:paddingBottom="@dimen/margin_small"
            android:paddingTop="@dimen/margin_small"
            android:text="注冊"
            android:textColor="@android:color/background_light"
            android:textSize="@dimen/text_size_normal" />
    </LinearLayout>
</LinearLayout>      

RegisterActivity.java

package com.hhn.asus.da;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.Toast;

import db.Sqlite;
import db.User;

public class RegisterActivity extends AppCompatActivity {
    //使用者名
    private ImageView img_account;
    private EditText et_account;

    //密碼
    private ImageView img_pw;
    private EditText et_password;

    //再次輸入密碼
    private ImageView img_pw_again;
    private EditText et_password_again;

    //注冊按鈕
    private Button btn_register;

    private String name,pass,passAgain;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_register);
        init();

        btn_register.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                getEditString();
                User user=new User();
                user.setUsername(name);
                user.setUserpwd(pass);
                int result= Sqlite.getInstance(getApplicationContext()).saveUser(user);
                if (TextUtils.isEmpty(name)) {
                    Toast.makeText(RegisterActivity.this,"請輸入使用者名",Toast.LENGTH_SHORT).show();
                    return;
                }else if(TextUtils.isEmpty(pass)){
                    Toast.makeText(RegisterActivity.this,"請輸入密碼",Toast.LENGTH_SHORT).show();
                    return;
                }else if(TextUtils.isEmpty(passAgain)){
                    Toast.makeText(RegisterActivity.this,"請再次輸入密碼",Toast.LENGTH_SHORT).show();
                    return;
                }else if(!pass.equals(passAgain)){
                    Toast.makeText(RegisterActivity.this,"兩次輸入的密碼不一緻",Toast.LENGTH_SHORT).show();
                    return;
                }else if(result==-1){
                    Toast.makeText(RegisterActivity.this,"此使用者名已存在",Toast.LENGTH_SHORT).show();
                    return;
                }else {
                    Toast.makeText(RegisterActivity.this,"注冊成功",Toast.LENGTH_SHORT).show();
                    RegisterActivity.this.finish();
                }
            }
        });
    }

    private void init(){//控件初始化
        img_account=(ImageView)findViewById(R.id.img_account);
        et_account=(EditText)findViewById(R.id.et_account);
        img_pw=(ImageView)findViewById(R.id.img_pw);
        et_password=(EditText)findViewById(R.id.et_password);
        img_pw_again=(ImageView)findViewById(R.id.img_pw_again);
        et_password_again=(EditText)findViewById(R.id.et_password_again);
        btn_register=(Button)findViewById(R.id.btn_register);
    }

    private void getEditString(){//擷取控件中的字元串
        name=et_account.getText().toString().trim();
        pass=et_password.getText().toString().trim();
        passAgain=et_password_again.getText().toString().trim();
    }
}      
【軟體工程Ⅱ】作業五 |結對項目-國小四則運算 “軟體”之更新版

(3)階乘運算

階乘計算這一部分我用的是随機出1-10的數的階乘,因為在剛開始設計這一部分時,我本來用的是100以内的數,但是後面發現計算量太大,是以改成10以内的數比較合理。

two.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@mipmap/two">

    <TextView
        android:id="@+id/timee"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="100dp"
        android:textColor="@color/ti"
        android:textSize="30dp" />

    <TextView
        android:id="@+id/tv_question"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_above="@+id/editText"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="46dp"
        android:textSize="25dp" />

    <EditText
        android:id="@+id/editText"
        android:layout_width="280dp"
        android:layout_height="50dp"
        android:layout_above="@+id/button"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="36dp"
        android:gravity="bottom"
        android:hint="請輸入答案"
        android:inputType="number"/>

    <Button
        android:id="@+id/button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="确定"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="95dp"/>

</RelativeLayout>      

two.java

package com.hhn.asus.da;

import android.content.Intent;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import java.util.Random;

/**
 * Created by ASUS on 2018/6/24.
 */

public class two extends AppCompatActivity{
    private TextView timee, question;
    private Button button;
    private EditText editText;

    String aa = "1";
    private MyCount mc;
    String da;
    int time;


    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.one);
        button = (Button) findViewById(R.id.button);
        editText = (EditText) findViewById(R.id.editText);
        timee = (TextView) findViewById(R.id.timee);
        question = (TextView) findViewById(R.id.question);
        PublicWay.activityList.add(this);
        mc = new two.MyCount(10000, 1000);
        mc.start();
        final float result = question();
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                float answer = Float.parseFloat(editText.getText().toString());
                //float answer=editText.getText().toString();
                if (answer == result) {
                    Toast.makeText(two.this, "你答對了", Toast.LENGTH_LONG).show();
                    return;
                } else {
                    Toast.makeText(two.this, "答錯了", Toast.LENGTH_LONG).show();
                }
            }
        });
    }


    ;

    class MyCount extends CountDownTimer {
        public MyCount(long millisInFuture, long countDownInterval) {
            super(millisInFuture, countDownInterval);
        }

        @Override
        public void onTick(long l) {
            time = (int) l / 1000;
            timee.setText("倒計時:" + time);
        }

        @Override
        public void onFinish() {
            Intent fail = new Intent();
            fail.setClass(two.this, fail.class);
            startActivity(fail);
        }
    }

    public float question() {
        final Random random = new Random();
        float result = 1;
        final int num1 = random.nextInt(10) + 1;//數字的随機生成

        for (int i = 1; i <= num1; i++) {
            result = i * result;
        }
        question.setText(num1 + "!" + "=");
        return result;
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if ("1".equals(aa)) {
            mc.cancel();
            mc = null;
        } else if ((!"1".equals(aa)) && "0".equals(time)) {
            Intent fail = new Intent();
            fail.setClass(two.this, fail.class);
            startActivity(fail);
        }
    }
}      

頁面運作結果如下:

【軟體工程Ⅱ】作業五 |結對項目-國小四則運算 “軟體”之更新版

五、結對程式設計軟體過程耗時估計與統計表

PSP2.1 Personal Software Process Stages Time
Planning 計劃  10
·Estimate 估計這個任務需要多少時間 20 
Development 開發 15 
·Analysis 需求分析 (包括學習新技術)
·Design Spec 生成設計文檔
· Design Review 設計複審
· Coding Standard 代碼規範 1.5 
· Design 具體設計 4.5 
· Coding 具體編碼 16 
· Code Review 代碼複審
· Test 測試(自我測試,修改代碼,送出修改)
·Reporting 報告
· 測試報告
計算工作量
并提出過程改進計劃

六、總結

 通過本次做這個app,使得我對于Android Studio的程式設計變得更加熟練,同時也更加深刻的了解了四則運算的功能,雖然本次做這個app花了不少時間,但是在後期調試時還是會發現不少Bug。對于本次作業我覺得我們小組有一點很重要的地方沒有做到的是命名的規範化,等到我們已經做完了才發現這個問題時改起來會比較困難,對于這個問題我們下次會注意的。