20162304 阶段编程四则运算(挑战出题)

20162304 阶段编程四则运算(挑战出题)

结对伙伴:20162318

需求分析

  1. 要能指定生成题目的数量
  2. 每次生成的题目不能有重复
  3. 要能指定题目包含的运算符数量
  4. 通过命令行参数形式指定题目要求
  5. 输出题目到文件,一行一个题目

设计思路

  1. 先进行中缀转后缀
  2. 对后缀进行排序
  3. 若后缀相同,则进行答案判断

UML类图

实现过程中的关键代码解释

public class Sort {
    private String result, str, result2, result3;

    // 排序(数字大小排序,非数字位置不变)
    public String sorting(String s) {
        String p = s.trim();
        String[] str = p.split(" ");
        List<String> list = new ArrayList<String>();
        for (int i = 0; i < str.length; i++) {
            //判断是不是数字
            if (isNumeric(str[i])) {
                list.add(str[i]);
            }
        }

        //排大小
        String[] strings = new String[list.size()];
        for (int i = 0; i < list.size(); i++) {
            strings[i] = list.get(i);
        }
        for (int x = 0; x < strings.length - 1; x++) {
            for (int y = x + 1; y < strings.length; y++) {
                int s1 = Integer.parseInt(strings[x]);
                int s2 = Integer.parseInt(strings[y]);
                if (s1 >= s2) {
                    String temp = strings[x];
                    strings[x] = strings[y];
                    strings[y] = temp;
                }
            }
        }
        int j = 0;
        for (int i = 0; i < str.length; i++) {
            //判断是数字还是符号
            if (isNumeric(str[i])) {
                str[i] = strings[j];
                j++;
            }
        }
        String c = " ";
        for (int i = 0; i < str.length; i++)
            c += (str[i] + " ");
        return c;
    }

    //判断是否为数字
    public boolean isNumeric(String str) {
        Pattern pattern = Pattern.compile("[0-9]*");
        Matcher isNum = pattern.matcher(str);
        if (!isNum.matches()) {
            return false;
        }
        return true;
    }
}

l1 = title.promber3(i + 1, 9, 4, 1);//生成题目
                    result1 = con.storage(l1);//中转后
                    result3 = eva.calculate(result1);//计算当前
                    result2 = sort.sorting(result1);//排序
                    if (list.size() != 0) {
                        for (int w = 0; w < list.size(); w++) {
                            //判断排序后的式子是否相同
                            if (result2.equals(list.get(w))) {
                                result4 = eva.calculate(list2.get(w));//计算排序后的式子相同的答案
                                if (result3.equals(result4)) {
                                    x = 1;
                                    s --;
                                    break;
                                }
                            }
                        }
                    }
                    if (x == 0) {
                        list.add(result2);//排序后的题目
                        list1.add(l1);//原题目
                        list2.add(result1);//中转后
                    }

测试方法

用老师给的程序进行测试。

运行过程截图


代码托管地址

遇到的困难及解决方法

遇到的困难就是运行的时候可能会出现崩溃的情况,不过在运行几次就好了。

对结对的小伙伴做出评价

我的结对伙伴比较给力,上星期就已经实现了本周的部分要求,然后要说有什么不足的话,希望以后我俩可以更默契一点吧。

给我的结对伙伴打分55分,在整个结对编程的过程中,泰毓同学教会了我很多东西,IDEA使用的一些小技巧啊啥的等等,总之跟感谢他。

PSP

PSP2.1 Personal Software Process Stages 预估耗时(小时) 实际耗时(小时)
Planning 计划 0.5 0.5
· Estimate · 估计这个任务需要多少时间 0.5 0.5
Development 开发 2.4 3
· Analysis · 需求分析 (包括学习新技术) 0.3 0.2
· Design Spec · 生成设计文档 0.1 0.2
· Design Review · 设计复审 (和同事审核设计文档) 0.5 1
· Coding Standard · 代码规范 (为目前的开发制定合适的规范) 0.2 0.2
· Design · 具体设计 0.2 0.2
· Coding · 具体编码 1 0.2
· Code Review · 代码复审 0.5 1
· Test · 测试(自我测试,修改代码,提交修改) 5 8
Reporting 报告 1.7 2.5
· Test Report · 测试报告 1 0.5
· Size Measurement · 计算工作量 0.5 0.1
· Postmortem & Process Improvement Plan · 事后总结, 并提出过程改进计划 0.2 0.5
总计 4.6 6
posted @ 2017-06-04 22:58  20162304张浩林  阅读(164)  评论(5编辑  收藏  举报