结对作业1----基于GUI的四则运算生成器

组员:201421123015 陈麟凤 201421123019 张志杰 201421123020 黄海鸿

coding 地址:代码点这里

需求分析:

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

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

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

4、程序基于GUI界面;

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

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

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

思维导图:

功能实现:

主要功能除了在第一次作业中的四则运算功能,增加了计时器功能、语言选择功能以及记录对错题总数的功能;

代码展示:

计时器:

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();

 

语言选择的部分代码:

mi1表示中文简体;mi2表示中文繁体;mi3表示英文;

        mi1.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                jlb.setText("请输入生成的题目数量:");
                jtf.getText();
                jb.setText("生成題目");                
            }
        });
        mi2.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                jlb.setText("請輸入生成的題目數量:");
                jtf.getText();
                jb.setText("生成題目");                
            }
        });
        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");                
            }
        });

对错题数目存入文件:

                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:/newfile.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();
                                }
                            }
                        }
                 });

测试运行:

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

PSP:

PSP2.1

Personal Software Process Stages

Time(min) Senior Student

Time (min)

Planning

计划

5

2

Estimate

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

3

10

Development

开发

3

0

Analysis

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

3

5

·Design Spec

生成设计文档

1

0

·Design Review

设计复审

1

0

Coding Standard

代码规范

10

5

· Design

具体设计

5

5

Coding

具体编码

60

250

·Code Review

代码复审

5

60

Test

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

10

5

Reporting

报告

5

3

 

测试报告

3

1

 

计算工作量

3

5

 

并提出过程改进计划

5

0

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

小结:

        本次的作业代码大部分基本由我完成,功能实现以及界面设计由小组内讨论,因为采用的是我的第一次作业为基础,而且我的编程能力稍微会好一点。

        起初小组的决定是完成计时器和语言选择功能就可以,将第一次的代码修改一下在加上GUI,然后在看需求添加相应的计时器功能和语言选择功能,但在后期程序基本完成时由张志杰同学添加了简单的记录错题数的功能,在写程序过程也遇到过不少问题,比如在获取输入的答案是会出现获取不到的情况,就是输入的答案没有传到变量里面,纠结了挺久,小组内讨论也是没办法立刻解决,还是后面才发现获取答案的时候用户还没有输入答案导致获取到的只是空值,最后觉得写程序的时候希望自己以及我的组员张志杰同学要有耐心一点,在编程遇到问题的时候冷静一点处理,以及感谢张志杰和黄海鸿同学在完成这次作业的过程中给予的建议。

 

 

 

 

 

posted on 2017-03-14 19:35  chenlinfeng  阅读(260)  评论(3编辑  收藏  举报