结对编程1

学号:

201421122078

201421122085

项目地址:https://coding.net/u/maobinggan/p/shishi/git

1 .需求分析

1把第一次作业的程序做成GUI,成为一个有基本功能、一定价值的程序。

2.记录用户的对错总数,程序退出再启动的时候,能把以前的对错数量保存并在此基础上增量计算。

3.有计时功能,能显示用户开始答题后的消耗时间。

4.界面支持中文简体/中文繁体/英语,用户可以选择一种;

2.程序设计

针对选择的2-3个新开发功能做设计,使用思维导图:

3.代码展示

3.1计时器代码

复制代码
        //计时器代码
        class shishi3 extends Thread {
            private long noww = 0l;
            private long start = System.currentTimeMillis();// 程序启动时间的毫秒值
            private long time;
            public void run() {
                int i=0;
                while (true) {

                    noww = System.currentTimeMillis();// 获取一秒之后的毫秒值
                    System.out.println("start="+start);
                    System.out.println("noww="+noww);
                    time = noww - start;// 两个时间相减的到毫秒差
                    System.out.println("time="+time);
                    System.out.println("(time / 1000 % 60)="+(time / 1000 % 60));
                    timetime=time;
                    String ssss=String.format("%02d:%02d:%02d\n",
                            time / (1000 * 60 * 60) % 60/* 时 */, 
                            time / (1000 * 60)% 60/* 分 */, 
                            (time / 1000 % 60)/* 秒 */);// 格式化字符串输出
               
                        l1.setText(ssss);
                        i++;
                        try {
                            Thread.sleep(1000);
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                    
                }
            }
复制代码

3.2从文件读取历史记录

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
//从文件读取历史记录
                try {
                    BufferedReader br3 = new BufferedReader(new FileReader(file3));
                    String s = null;    
                  
                    before = br3.readLine();
                    if(before==null) {
                        totalright=now;
                    }else {
                        totalright=Integer.parseInt(before)+now;
                        System.out.println("直接打印String类型的before"+before);
                        br3.close();    
                    }
                  
                } catch (Exception e3) {
                    e3.printStackTrace();
                }
                System.out.println("try1结束");
                System.out.println("try2");
                try {
                    PrintWriter pw3 = new PrintWriter(file3);
                    pw3.println(totalright);
                    pw3.close();
                } catch (IOException e1) {
                    // TODO Auto-generated catch block
                    e1.printStackTrace();
                }
                System.out.println("try2结束");
                JOptionPane.showMessageDialog(null, co+"\n"+fi+"\n"+"用时:"+(timetime / 1000 % 60)+"秒\n"+"本次答对:"+now+"题"+"\n"+"累计答对:"+totalright+"题");

  

4.程序运行

初始界面:

开始答题

点击提交查看对错:

点击下一页按钮翻页:

 

 

点击结束答题按钮查看统计结果

5.小结感受:结对编程真的能够带来1+1>2的效果吗?

人都有思维局限性和薄弱点,我们在写代码的过程中常常会进入一个死胡同里,结对编程的话,可以互相帮助提高编程效率。

6.运用“汉堡包”的方式,评价你的合作伙伴,指出优点、缺点,希望ta提高的地方。

在完成代码编程之前,我们一起讨论采用哪些算法思想。在完成代码编程之后,我们一起讨论如何优化完善代码。思维活跃和细心是他的一个优点,大部分的bug都是由他发现的。至于缺点,写代码不够规范,有时候我读不懂他的代码。

7.PSP表格

 

posted on 2017-10-22 18:48  Mr吉祥物  阅读(145)  评论(0编辑  收藏  举报

导航