结对项目——四则运算
一、github地址
https://github.com/kinglc/AutoCalculator
二、PSP
|
PSP2.1 |
Personal Software Process Stages |
预估耗时(分钟) |
实际耗时(分钟) |
|
Planning |
计划 |
30 |
30 |
|
·Estimate |
·估计这个任务需要多少时间 |
30 |
30 |
|
Development |
开发 |
2010 |
2160 |
|
·Analysis |
·需求分析(包括学习新技术) |
480 |
400 |
|
·Design Spec |
·生成设计文档 |
60 |
50 |
|
·Design Review |
·设计复审 |
30 |
30 |
|
·Coding Standard |
·代码规范 |
30 |
60 |
|
·Design |
·具体设计 |
240 |
300 |
|
·Coding |
·具体编码 |
900 |
1080 |
|
·Code Review |
·代码复审 |
90 |
60 |
|
·Test |
·测试 |
180 |
180 |
|
Reporting |
报告 |
70 |
70 |
|
·Test Report |
·测试报告 |
30 |
30 |
|
·Size Measurement |
·计算工作量 |
10 |
10 |
|
·Postmortem&Process Improvement Plan |
·事后总结并提出过程改进计划 |
30 |
30 |
|
|
合计 |
2110 |
2260 |
三、设计思路
1.整个项目包括生成题目及存储、解题、GUI、倒计时及历史记录功能。(队友博客地址https://home.cnblogs.com/u/shera)
2.解题:
按优先级分为小括号、两种乘方、乘除和加减。用while处理完算式中所有包含该运算符的部分,依次往后确定优先级。使用substring获取计算的数字,转为BigDecimal类型提高精度。
乘方运算中由于pow函数参数为double,为了保证精度此处使用for循环进行计算。
View Code
分数单独开一个类,分为分子,分母进行计算。类中内含加减乘除约分方法,其中约分为private。
View Code3.GUI
使用自由度相对较高的FlowLayout进行布局,添加JLabel,JButton,JTextField控件。对于乘方的设置:
1 jrb1.setFont(new java.awt.Font("Dialog", 1, 15));
2 jrb2.setFont(new java.awt.Font("Dialog", 1, 15));
3 ButtonGroup bg = new ButtonGroup();
4 bg.add(jrb1);
5 bg.add(jrb2);
6 jrb1.setSelected(true);
4.倒计时
使用Thread.sleap(1000)计时,若不提交答案时间结束则重置时间,减少生命,并重置算式。
1 while (time >= 0) {
2 jltime.setText( "" + time );
3 try {
4 Thread.sleep(1000);
5 } catch (InterruptedException e) {
6 e.printStackTrace();
7 }
8 time--;
9 if(time==-1) {
10 time=20;
11 life--;
12 jllife.setText("生命"+life);
13 jltime.setText("时间"+time);
14 Create c= new Create(power_form);
15 jlformula.setText(c.formula);
16
17 }
18 }
5.历史记录
新建一个score.txt文件,每次得分为0时FileWriter.writer会在文件末尾写入时间和得分,并弹窗显示最新的十条记录。
1 try {
2 Calendar c = Calendar.getInstance();
3 FileWriter writer = new FileWriter(scorefile, true);
4 writer.write(c.get(Calendar.MONTH)+1+"月"+c.get(Calendar.DAY_OF_MONTH)+"日"
5 +c.get(Calendar.HOUR_OF_DAY)+"时"+c.get(Calendar.MINUTE)+"分" +
6 " 得分: "+score+"\n");
7 writer.close();
8 } catch (IOException e1) {
9 e1.printStackTrace();
10 }
11 try {
12 time=-2;
13 showscores();
14 end();
15 } catch (IOException e1) {
16 e1.printStackTrace();
17 }
1 public void showscores() throws IOException {
2 BufferedReader bfr = new BufferedReader(new FileReader(scorefile));
3 String score[]= new String[1000];
4 String s,ans="";
5 int pos=0;
6 while ((s=bfr.readLine())!=null){
7 score[pos++]=s;
8 }
9 for(i=pos-10;i<pos;i++)
10 if(i>=0){
11 ans+=score[i]+"\n";
12 }
13 JOptionPane.showMessageDialog(null, ans, "历史记录", JOptionPane.INFORMATION_MESSAGE);
14
15 }
16
17 public void end(){
18 System.exit(0);
19 }
三、总结
首先从知识方面,熟悉了java的GUI,对文件的操作,加深了类的认识,更了解了一些此前完全没有接触过的类和方法。
从项目经验来说,结对项目就存在着交互。项目一共四个类,Fraction和Calculator是我写的,Create是队友写的,Fraction只在Calculator中调用,都没有什么大问题。而MainJF是不断在两个人之间交替,我写完GUI计时计算,队友接着写生成,生成之后两人一起研究历史记录,历史记录有涉及到之前的计时,就会难免杂乱。不过也是由于其他事情比较多没有在一段时间内专心做这一项,没能顺畅地走下一套流程。不过这也是很难得的一次经历了。


浙公网安备 33010602011771号