结对编程1-四则运算

代码地址:

https://coding.net/u/q596926716/p/dfs/git/upload/master/

结对伙伴:黄子敬

一、题目要求

将第一次作业中的四则运算程序做成GUi界面的形式展示出来,要求在下面的功能需求中实现两个:

1.记录用户的对错总数,程序退出再启动的时候,能把以前的对错数量保存并在此基础上增量计算。
2.有计时功能,能显示用户开始答题后的消耗时间。
3.界面支持中文简体/中文繁体/英语,用户可以选择一种

二、需求分析:

1、除了整数的四则运算还要支持分数的四则运算;

2、运算符为 +, −, ×, ÷;

3、能处理用户的输入,包括分数;

4、程序基于GUI界面;

5、能记录用户做题的对错数量,下次使用程序时能在之前的数量上增加;

6、有计时功能,能显示用户开始答题后的消耗时间

7、界面支持中文简体/中文繁体/英文,用户选择一种

三、功能实现:

1.除了在第一次作业中的四则运算功能,增加了计时器功能、语言选择功能以及记录对错题总数的功能;
2.其中对错题数通过文件来生成表示;

四、功能导图:

五、部分代码展示:

1、语言选择部分

mi1.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                jlb.setText("请输入题目数量,为您生成题目");
                jtf.getText();
                jb.setText("go!");                
            }
        });
        mi2.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                jlb.setText("請輸入題目數量,為您生成題目");
                jtf.getText();
                jb.setText("go!");                
            }
        });
        mi3.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                jlb.setText("please input the number of questions you want:");
                jtf.getText();
                jb.setText("generate tests");                
            }
        });

2、统计正确以及错误题目部分代码:

复制代码
 jbt.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    File file = new File("D:/newfile.txt");
                    String line =null;
                    try {
                        BufferedReader br = new BufferedReader(new FileReader(file));
                         try {
                             while((line = br.readLine()) != null){
                                 String[] num = line.split("#");
                                 zheng1=Integer.parseInt(num[1]);
                                 cuo1=Integer.parseInt(num[3]);
                             }} catch (IOException ex) {
                             Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex);
                         }
                    } catch (FileNotFoundException ex) {
                        keep();
                    }
                     keep();
                 }
                private void keep() {
                    FileOutputStream fop = null;
                    File file;
                    String content = "正确#"+(n-MainFrame.cuowu+zheng1)+"#错误#"+(MainFrame.cuowu+cuo1)+"#";
                    try {
                        file = new File("D:/result.txt");
                        fop = new FileOutputStream(file);
                        if (!file.exists())
                        {
                            file.createNewFile();
                        }
                        byte[] contentInBytes = content.getBytes();
                        fop.write(contentInBytes);
                        fop.flush();
                        fop.close();
                        } catch (IOException e) {
                            e.printStackTrace();
                        } finally {
                            try {
                                if (fop != null) 
                                {
                                    fop.close();
                                }
                                } catch (IOException e) {
                                    e.printStackTrace();
                                }
                            }
                        }
                 });

3、计数器部分:

now.setHours(0);
now.setMinutes(0);
now.setSeconds(0);
final Timer timer = new Timer(1000, new ActionListener() {
    public void actionPerformed(ActionEvent e) {
        Date now2 = new Date(now.getTime() + 1000);
        now = now2;
        SimpleDateFormat formatter = new SimpleDateFormat("HH:mm:ss");
        lbl.setText(formatter.format(now));
        }
        });
    timer.start();

六、运行测试截图:

主界面:

语言选择:

开始出题:

记录文本:

七、PSP表格

PSP2.1

Personal Software Process Stages

Estimated time(h)

actual time(h)

Planning

计划

1

1.2

· Estimate

估计这个任务需要多少时间

10

18

Development

开发

8

12

· Analysis

需求分析 (包括学习新技术)

1

2

· Design Spec

生成设计文档

0.5

0.5

· Design Review

设计复审

0.5

0.6

· Coding Standard

代码规范

0.5

0.3

· Design

具体设计

1.5

1.5

· Coding

具体编码

6

7.5

· Code Review

代码复审

0.5

0.8

· Test

测试(自我测试,修改代码,提交修改)

1.5

1.6

Reporting

报告

1

1

·

测试报告

 0.5  

 0.5

·

计算工作量

1

1

·

并提出过程改进计划

1

1

 

     
       

附上与猪队友的合照:

 

八、总结

原本上次的四则运算是用C++写的,但是这次要实现GUI,经过和组员讨论商量,决定使用java来做GUI界面。这次思路清晰,目标明确,实现语言切换,实现计时器,实现累计题目数统计。
在这过程中,还是存在着在编译的过程中,老是犯了一些小错误,浪费了时间精力,还有的是队友有时没能够明白自己写的代码,所以代码的规范性很有必要。

posted on 2017-03-14 22:41  从小就很酷  阅读(178)  评论(1编辑  收藏  举报

导航