[软件工程]结对项目四则运算 “软件”之升级版

作业要求:https://edu.cnblogs.com/campus/gzcc/GZCC-16SE2/homework/2232

团队git代码:https://github.com/Hongnnn/ruanjiangongcheng


一、需求分析

     基本要求:

  • 生成题目,单个题目最多不能超过4个运算符,操作数小于100。
  • 用户可以输入答案
  • 若用户输入答案正确,则提示正确;若答案错误,则提示错误,并要提示正确答案是多少。

     扩展方向: 

      1.程序可以出带括号的正整数四则运算,支持分数,除法保留两位小数,如:(1/3+1)*2 = 2.67,特别注意:这里是2.67而非2.66,或保持分数形式:8/3

      2.可以出表达式里含有负整数(负整数最小不小于-100)的题目,且负数需要带括号,用户输入的结果不用带括号。如: 2*(-4) = -8

      3.用户答题结束以后,程序可以显示用户答题所用的时间

      4.用户可以选择出题的个数(最多不能超过5个题目),答题结束可以显示用户答错的题目个数和答对的题目个数

      5.用户在第一次答题时,需要用户输入用户名,用户下次启动后,程序需要记住用户前一次输入的用户名 

      6.程序可以出单个整数阶乘的题目:如:4!=24

      7.程序可以设置答题时间,时间设置为整数,单位为秒,最大不能超过120秒,若超过了答题时间未答题,则提示:时间已到,不能答题。

      8.程序可以设置皮肤功能,可以改变界面的颜色即可。


 二、开发环境

开发工具:Android Studio 2.3.3

开发语言:java

开发时间:2018.10.25-2018.10.29


三、详细设计

团队所实现的拓展方向为:

    1.程序可以出带括号的正整数四则运算,支持分数,除法保留两位小数,如:(1/3+1)*2 = 2.67,特别注意:这里是2.67而非2.66,或保持分数形式:8/3

      3.用户答题结束以后,程序可以显示用户答题所用的时间

      4.用户可以选择出题的个数(最多不能超过5个题目),答题结束可以显示用户答错的题目个数和答对的题目个数

      5.用户在第一次答题时,需要用户输入用户名,用户下次启动后,程序需要记住用户前一次输入的用户名 

      6.程序可以出单个整数阶乘的题目:如:4!=24

      7.程序可以设置答题时间,时间设置为整数,单位为秒,最大不能超过120秒,若超过了答题时间未答题,则提示:时间已到,不能答题。

设计流程:

    用户进行答题界面,点击进入答题即需要输入用户名,成功则可以进入答题,进入答题时会可以选择要答多少道题,数字和运算符都是随机生成的,答案需要点击确定按钮之后会用Toast告诉说答错还是答对~同时在结束后会统计答对多少,答错多少,用时多久~


 四、主要代码

 1.首页布局

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center"
    android:background="@mipmap/one">
/>
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="四则运算"
        android:textColor="@color/pink_pressed"
        android:textSize="@dimen/dp_35"/>
    <Button
        android:id="@+id/jinru"
        android:layout_marginTop="15dp"
        android:layout_width="@dimen/dp_200"
        android:layout_height="wrap_content"
        android:text="进入答题"
        android:textSize="@dimen/dp_20"
        android:background="@drawable/border"
 />
    <Button
        android:id="@+id/guize"
        android:layout_width="@dimen/dp_200"
        android:layout_marginTop="@dimen/dp_30"
        android:layout_height="wrap_content"
        android:text="答题规则"
        android:background="@drawable/border"
        android:textSize="@dimen/dp_20"/>
 <Button
     android:id="@+id/tuic"
     android:layout_width="@dimen/dp_200"
     android:layout_marginTop="@dimen/dp_30"
     android:layout_height="wrap_content"
     android:text="退出"
     android:background="@drawable/border"
     android:textSize="@dimen/dp_20"/>
</LinearLayout>

 2.答题界面布局

  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:textSize="30dp"
          android:textColor="@color/ti"
          android:layout_alignParentTop="true"
          android:layout_centerHorizontal="true"
          android:layout_marginTop="100dp" />
    <TextView
        android:id="@+id/question"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="25dp"
        android:layout_marginBottom="46dp"
        android:layout_above="@+id/editText"
        android:layout_centerHorizontal="true"
/>
    
    <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>

 3.随机数的生成,其中包括生成数字的多少个,比如生成2个的话那就相当于 a+运算符+b=

   final Random random = new Random();
        int count = random.nextInt(3) + 2;  /*指定生成数字的多少个
        int signal1 = random.nextInt(4);
        int signal2 = random.nextInt(4);   //运算符的随机生成
        int signal3 = random.nextInt(4);


        float result = 0;
        final int num1 = random.nextInt(100) + 1;
        final int num2 = random.nextInt(100) + 1;   //数字的随机生成
        final int num3 = random.nextInt(100) + 1;
        final int num4 = random.nextInt(100) + 1;

4.题目的自动生成

 char fh[] = {'+', '-', '×', '÷'};
        if (count == 2) {
            question.setText(num1 + " " + fh[signal1] + " " + num2 + "=");
        } else if (count == 3) {
            question.setText(num1 + " " + fh[signal1] + " " + num2 + " " + fh[signal2] + "" + num3 + "=");
        } else {
            question.setText(num1 + " " + fh[signal1] + " " + num2 + " " + fh[signal2] + "" + num3 + "" + fh[signal2] + "" + num4 + "=");
        }

 5.Toast输出

  button.setOnClickListener(new View.OnClickListener() {
                                   @Override
                                   public void onClick(View view) {
                                       float answer = Float.parseFloat(editText.getText().toString());
                                       if (answer == result) {
                                           Toast.makeText(one.this, "你答对了", Toast.LENGTH_SHORT).show();
                                       } else {                               
                                           Toast.makeText(one.this, "你答错了", Toast.LENGTH_LONG).show();
                                       }

更多在github啦~


 五、程序展示

1.首页 

2.出题页面

 3.答题界面

 


六、结对同伴

姓名:陈碧环

分工:

陈碧环:登录注册界面,阶乘;

我:运算结果,倒计时,答题统计


七、结对软件过程耗时估计与统计表

PSP2.1 Personal Software Process Stages Time Senior Student(h) Time(h)
Planning 计划 1 10
· Estimate 估计这个任务需要多少时间 10 20
Development 开发 10 15
· Analysis 需求分析 (包括学习新技术) 1 1
· Design Spec 生成设计文档 1 1
· Design Review 设计复审 1 1
· Coding Standard 代码规范 1 1.5
· Design 具体设计 4 4.5
· Coding 具体编码 8 16
· Code Review 代码复审 1 1.5
· Test 测试(自我测试,修改代码,提交修改) 1 1
Reporting 报告 1 3
· 测试报告 0 0
· 计算工作量 1 1
· 并提出过程改进计划 0 1




八、个人总结

    在本次的结队项目中,发现了自己有很多知识点都忘了,好比如字符串的转换之类的,参数的传输,总结了一下就是JAVA语言学的是真的不怎么样,就是那种想做什么就找下关键的函数方法,重新看了一下一些方法的使用,数学一直不是很好,对数字的转换一直觉得很难,逻辑转换找不到错误,最后通过请师兄帮忙解决~通过这次的学习让我补了一些知识,是感觉挺不错的啦~

原文地址:https://www.cnblogs.com/hongna/p/9869892.html