1.项目成员#
- 学号:201521123014 博客地址:http://www.cnblogs.com/huangsh/
- 学号: 201521123102 博客地址:http://home.cnblogs.com/u/hyy786030686/
- 结对编程码云项目地址:https://gitee.com/huangsh1/software_pair_programming
2.改进现有代码#
原始代码思维导图:###
覆盖率统计截图:###
发现的问题:
- 简繁英的切换不完善(鼠标事件监听异常)
- 代码编码不规范
- 复习错题集不完善
- 统计率不正确
改进与扩展(需求分析):
1)规范了代码样式;
2)修正了简繁英切换的问题;
3)修改了界面左下角正确率显示不正确的问题。
4)加入了乘方和括号的表达式
5)优化了复习错题集
3.程序设计#
思维导图:###
关键代码展示:###
语言切换:
Simplified_Chinese.setText("简");
Simplified_Chinese.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
Simplified_ChineseMouseClicked(evt);
}
});
Traditional_Chinese.setText("/繁");
Traditional_Chinese.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
Traditional_ChineseMouseClicked(evt);
}
});
English.setText("/English");
English.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
EnglishMouseClicked(evt);
}
});
创建答题历史记录和错题集:
public void Histroy_create() {
String path = "f:\\Myapp";
File f = new File(path);
if (!f.exists()) {
f.mkdirs();
String fileName = "histroy.txt";
File file = new File(f, fileName);
if (!file.exists()) {
Writer writer = null;
try {
writer = new OutputStreamWriter(new FileOutputStream(file), "UTF-8");
} catch (UnsupportedEncodingException | FileNotFoundException e) {
e.printStackTrace();
}
try {
if (writer != null) {
writer.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
f.mkdirs();
String fileName2 = "histroy_num.txt";
File file2 = new File(f, fileName2);
if (!file2.exists()) {
Writer writer = null;
try {
writer = new OutputStreamWriter(new FileOutputStream(file2), "UTF-8");
} catch (UnsupportedEncodingException | FileNotFoundException e) {
e.printStackTrace();
}
try {
if (writer != null) {
writer.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
Histroy_saveNum();
}
}
public void Histroy_save() {
FileWriter writer;
String fileName = ("f:\\Myapp\\histroy.txt");
try {
writer = new FileWriter(fileName, true);
writer.write(str);
writer.write("\r\n");
writer.close();
} catch (IOException e) {
e.printStackTrace();
}
}
public void Histroy_saveNum() {
FileWriter writer2;
String fileName2 = ("f:\\Myapp\\histroy_num.txt");
try {
writer2 = new FileWriter(fileName2, true);
writer2.write(str2);
writer2.write("\r\n");
writer2.close();
} catch (IOException e) {
e.printStackTrace();
}
}
括号:
for (int j = 0; j < leftNums; j++) {
exp += "(";
}
if (exp.length() > leftNums && exp.charAt(exp.length() - leftNums - 1) == '^') {
int matchPos = i + 1;
for (int j = 0; j < leftNums; j++) {
exp = exp.substring(0, exp.length() - 1);
while (rightPosMap.get(matchPos) <= 0) {
matchPos++;
}
rightPosMap.put(matchPos, rightPosMap.get(matchPos) - 1);
}
exp += random.nextInt(4);
} else {
int generateNum = (random.nextInt(40) - 20);
if (generateNum < 0 && (leftPosMap.get(i + 1) == 0 || rightPosMap.get(i + 1) == 0)) {
exp += "(" + generateNum;
rightPosMap.put(i + 1, rightPosMap.get(i + 1) + 1);
} else {
exp += generateNum;
}
}
int rightNums = rightPosMap.get(i + 1);
for (int j = 0; j < rightNums; j++) {
exp += ")";
}
去除产生除0:
public static ArrayList<ExpAndAns> generateExps(int num) {
HashSet<MinPreFormat> hashSet = new HashSet<>();
ArrayList<ExpAndAns> res = new ArrayList<>();
for (int i = 0; i < num; i++) {
String exp = generateNewExp();
String postexp = trans(exp);
Node root = createExpTree(postexp);
MinPreFormat minPreFormat = minPre(root);
if (hashSet.contains(minPreFormat)) {
i--;
} else {
Rational ans = calc(postexp);
if (ans.getM_down() == 0) {
i--;
} else {
hashSet.add(minPreFormat);
res.add(new ExpAndAns(exp, ans));
}
}
}
return res;
}
程序运行截图###
主界面:
答题界面:
错题集:
历史记录:
覆盖率:
码云提交记录#
两人合作#
- psp表格
小结#
初次接触到结对编程,一开始的困难还是很大的,毕竟是异性,不是在同一个宿舍。只能跑图书馆。结对编程应该是类似于驾驶员和领航员的关系,但是在实践过程中确实有些困难,因为基础不是特别扎实,所以在前面一周基本都在复习JAVA的知识。看源代码的过程也会有点费解,花的时间比较长。但是总比一个人编程好。在结对过程中,一旦你有什么错误,对方都能帮你及时指正。总而言之还是有1+1>2的。