韩华颂 2016282110142 

  吴政楠 2017282110286

1 项目Github地址

  https://github.com/songofjoy/softwareProject

2 预估耗时

PSP2.1 Personal Software Process Stages 预估耗时(分钟) 实际耗时(分钟)
Planning 计划 10  10
· Estimate · 估计这个任务需要多少时间   10     10
Development 开发 1140  1360
· Analysis · 需求分析 (包括学习新技术)   60    80
· Design Spec · 生成设计文档   60    80 
· Design Review · 设计复审 (和同事审核设计文档)   30    40 
· Coding Standard · 代码规范 (为目前的开发制定合适的规范)   30    40 
· Design · 具体设计   60    70 
· Coding · 具体编码   600   700 
· Code Review · 代码复审   180    200 
· Test · 测试(自我测试,修改代码,提交修改)   120    150 
Reporting 报告 180  150 
· Test Report · 测试报告   150    120 
· Size Measurement · 计算工作量   10    10 
· Postmortem & Process Improvement Plan · 事后总结, 并提出过程改进计划   20   20 
合计   1330 1520

3 解题思路

  3.1 前期准备

    在上一次作业中,我们已经生成了一个简单的算式生成器,但是其中还有括号的功能没有实现。基础代码选取了我们两人中性能较高的一个,本次项目不仅要实现GUI,还要在之前的基础上实现括号。

  3.2 后端

    以上次的作业为基础,继续对上次的作业进行更一步的开发——添加括号。

  3.3 前端

    通过利用windowbuilder插件,可以将GUI展现给用户。

  3.4 分歧解决

    在最开始设计时,我们对GUI的呈现方式产生了分歧:

    1、以计算器的形式展现

    2、以网页的方式展现

    后来经过讨论,从时间角度和熟练程度考虑选取了以计算器的方式展示。  

4 设计实现过程

  4.1 获取题目

textField.setText(Equation.createEquation().toString());

  其中Equation是一个随机生成算式的函数

  4.2 保存统计数据

public static void saveScore(Score score) throws IOException, ParseException {
        
        FileWriter writer = new FileWriter(FILENAME);
        writer.write(score.getRightAmount() + SPLITSTRING);
        writer.write(score.getWrongAmount() + SPLITSTRING);
        writer.write(score.getRadioAmount() + SPLITSTRING);
        
        writer.close();
    }

  4.3 读取统计数据

public static Score readScore() throws IOException, ParseException {

        Score score=new Score();
        BufferedReader reader = new BufferedReader(new FileReader(FILENAME));
        String line = reader.readLine();
        String []infos=line.split(SPLITSTRING);
        score.setRightAmount(Integer.valueOf(infos[0]));
        score.setWrongAmount(Integer.valueOf(infos[1]));
        score.setRadioAmount(Double.valueOf(infos[2]));

        return score;

    }

  4.4 计时器

  对计时器进行的初始化设置

static int timer=0;
    static long starttimer=0;
    DecimalFormat df= new DecimalFormat("######0.0");  

 

  4.5 多语言支持

static final String EN="resource_english";
    static final String CH="resource_zh_CN_1";
    static final String HARD="resource_hard";

5 代码说明

  5.1显示当前数据

  将当前的正确题目数、错误题目数以及正确率记录在dat文件中,每次答题完成后点击下一题都会读取文件显示当前的答题数据并切换到下一题。

public void actionPerformed(ActionEvent e) {
                String[] strings=textField.getText().split("=");
                  DoubleStack testStack = new DoubleStack(strings[0]);  
                   testStack.analysisString();  
                String right=testStack.compute();
                if(strings.length>1&&strings[1].equals(right)){
                    textField1.setText("正确!");
                    curScore.setRightAmount(curScore.getRightAmount()+1);
                    System.out.println(curScore.getRightAmount());
                    System.out.println(curScore.getWrongAmount());
                    curScore.setRadioAmount((double)curScore.getRightAmount()/(double)(curScore.getRightAmount()+curScore.getWrongAmount()));
                    System.out.println(curScore.getRadioAmount());
                    lblNewLabel_1.setText(String.valueOf(curScore.getRightAmount()));
                    label_2.setText(String.valueOf(curScore.getWrongAmount()));
                    label_3.setText(String.valueOf(df.format(curScore.getRadioAmount()*100))+"%");

                    try {
                        Util.saveScore(curScore);
                    } catch (IOException | ParseException e1) {
                        // TODO Auto-generated catch block
                        e1.printStackTrace();
                    }
                }
                else{
                    textField1.setText("错误!正确答案为"+right);
                    curScore.setWrongAmount(curScore.getWrongAmount()+1);
                    curScore.setRadioAmount((double)curScore.getRightAmount()/(double)(curScore.getRightAmount()+curScore.getWrongAmount()));
                    lblNewLabel_1.setText(String.valueOf(curScore.getRightAmount()));
                    label_2.setText(String.valueOf(curScore.getWrongAmount()));
                    label_3.setText(String.valueOf(df.format(curScore.getRadioAmount()*100))+"%");

                    try {
                        Util.saveScore(curScore);
                    } catch (IOException | ParseException e1) {
                        // TODO Auto-generated catch block
                        e1.printStackTrace();
                    }
                }
                textField.setText(Equation.createEquation().toString());
            }
        });
View Code

相关文章:

猜你喜欢
  • 2021-05-25
  • 2022-01-29
  • 2021-12-13
  • 2021-12-09
  • 2021-09-26
  • 2022-02-08
相关资源
相似解决方案