您的位置:首页 > 编程语言

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

2017-06-04 22:58 253 查看

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

结对伙伴:20162318

需求分析

要能指定生成题目的数量

每次生成的题目不能有重复

要能指定题目包含的运算符数量

通过命令行参数形式指定题目要求

输出题目到文件,一行一个题目

设计思路

先进行中缀转后缀

对后缀进行排序

若后缀相同,则进行答案判断

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.1Personal Software Process Stages预估耗时(小时)实际耗时(小时)
Planning计划0.50.5
· Estimate· 估计这个任务需要多少时间0.50.5
Development开发2.43
· Analysis· 需求分析 (包括学习新技术)0.30.2
· Design Spec· 生成设计文档0.10.2
· Design Review· 设计复审 (和同事审核设计文档)0.51
· Coding Standard· 代码规范 (为目前的开发制定合适的规范)0.20.2
· Design· 具体设计0.20.2
· Coding· 具体编码10.2
· Code Review· 代码复审0.51
· Test· 测试(自我测试,修改代码,提交修改)58
Reporting报告1.72.5
· Test Report· 测试报告10.5
· Size Measurement· 计算工作量0.50.1
· Postmortem & Process Improvement Plan· 事后总结, 并提出过程改进计划0.20.5
总计4.66
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: