201571030117/201571030142 《小学四则运算练习软件》结对项目报告

一、guthub地址:https://github.com/iylong/sizeyunsuanlianxiruanjian

二、项目报告

1、需求分析

  (1)由计算机从题库文件中随机选择20道加减乘除混合算式,用户输入算式答案,程序检查答案是否正确,每道题正确计5分,错误不计

分,20道题测试结束后给出测试总分;

  (2)题库文件可采用实验二的方式自动生成,也可以手工编辑生成,文本格式如下:

(3)程序为用户提供三种进阶四则运算练习功能选择:百以内整数算式、带括号算式、真分数算式练习;

(4)程序允许用户进行多轮测试,提供用户多轮测试分数柱状图,如图2所示;

(5)程序记录用户答题结果,当程序退出再启动的时候,可为用户显示最后一次测试的结果,并询问用户可否进行新一轮的测试;

(6)测试有计时功能,测试时动态显示用户开始答题后的消耗时间;

(7)程序人机交互界面是GUI界面(WEB页面、APP页面都可),界面支持中文简体/中文繁体/英语,用户可以进行语种选择。

3.设计实现

三.核心代码展示

1.计算式的产生

 1 public void createTest() {
 2         // 定义一个随机数
 3         Random random = new Random();
 4         /*
 5          * 定义两个个Fractions对象,分别为: 第一个运算数 第二个运算数
 6          */
 7         Fractions fractions_1 = new Fractions();
 8         Fractions fractions_2 = new Fractions();
 9         // 定义Caculate对象用于计算结果
10         Caculate caculate = new Caculate();
11         // 生成10道题
12         for (int i = 0; i < testNum; i++) {
13             // 分别随机 生成第一个和第二个运算数并储存到question字符串集里
14             fractions_1.setValue(random.nextInt(diffculty) + 1, random.nextInt(diffculty) + 1);
15             question_1[i] = fractions_1.getFraction();
16             fractions_2.setValue(random.nextInt(diffculty) + 1, random.nextInt(diffculty) + 1);
17             question_2[i] = fractions_2.getFraction();
18             caculate.setOperationNum(fractions_1, fractions_2);
19             // 随机生成符号并计算结果存储到result字符串集
20             switch (random.nextInt(4)) {
21             // 加法运算
22             case 0:
23                 operator[i] = "+"; // 储存运算符
24                 result[i] = caculate.addtion().getFraction(); // 获取运算结果
25                 break;
26             // 减法运算
27             case 1:
28                 operator[i] = "-";
29                 result[i] = caculate.subtraction().getFraction();
30                 break;
31             // 乘法运算
32             case 2:
33                 operator[i] = "*";
34                 result[i] = caculate.multiplication().getFraction();
35                 break;
36             // 除法运算
37             case 3:
38                 operator[i] = "÷";
39                 result[i] = caculate.division().getFraction();
40                 break;
41             }
42         }
43     }
44 
45     // 传入一组答案,校验答案
46     public String[] checkAnswer(String[] answers) {
47         for (int i = 0; i < testNum; i++) {
48             // 如果答错了记下题号
49             if (!result[i].equals(answers[i])) {
50                 scoresList.add(new Integer(i + 1).toString());
51             }
52         }
53         String[] str = new String[scoresList.size()];
54         scoresList.toArray(str);
55         return str; // 返回一个得分集
56     }
57 
58     // 获取完整的题目
59     public String[] getQuestions() {
60         String[] questions = new String[testNum];
61         for (int i = 0; i < testNum; i++)
62             questions[i] = question_1[i] + "   " + operator[i] + "   " + question_2[i] + "  =  ";
63         return questions;
64     }
65 
66     // 获取标准答案
67     public String[] getStandardAnswer() {
68         return result;
69     }
70 
71     
72     /**
73      * 保存成绩到文件
74      * @throws FileNotFoundException 
75      */
76     public static void addscore(Integer score) throws FileNotFoundException {
77         String form = date.format(new Date());
78         PrintWriter pw = new PrintWriter(new File("history/scores.txt"));
79         if (scores.size() >= 10) {//最多十次数据
80             scores.remove(0);
81         }
82         scores.add(form + "-----" + score);
83         for (String string : scores) {
84             pw.println(string);
85         }
86         pw.flush();
87         pw.close();
88     }
89     
View Code

 2.同意校验答案,并统计错题号

 1 public void actionPerformed(ActionEvent e) {
 2         if (e.getSource() == btnSubmit) {
 3             isEnd = !isEnd; // 计时结束
 4             for (int i = 0; i < Background.testNum; i++) {
 5                 answers[i] = tfdAnswer[i].getText(); // 提取用户的答案
 6             }
 7             wrong = background.checkAnswer(answers); // 获得错题题号
 8             String l = String.valueOf(Background.testNum - wrong.length);
 9             count_array.add(l);
10             for (String e1 : count_array) {
11                 System.out.println(e1);
12             }
13             // 编辑反馈表
14             String s = null;
15             if (wrong.length == 0)
16                 s = tips.get(5);
17             else {
18                 s = tips.get(6) + "\n";
19                 String standardAnswer[] = new String[Background.testNum];
20                 standardAnswer = background.getStandardAnswer();
21                 for (int i = 0; i < wrong.length; i++) {
22                     s = s + new Integer(wrong[i]) + ":"
23                             + standardAnswer[new Integer(wrong[i]) - 1];
24                     s = s + "\n";
25                 }
26             }
27             JOptionPane.showMessageDialog(null, s, "report",
28                     JOptionPane.PLAIN_MESSAGE);
29 
30             int score = Background.testNum - wrong.length;
31             try {
32 
33                 Background.addscore(score * 10);
34             } catch (FileNotFoundException e2) {
35                 // TODO Auto-generated catch block
36                 e2.printStackTrace();
37             }
38         }
39         if (e.getSource() == btnReset) {
40             // this.dispose();
41             JFreeChartshow chart = new JFreeChartshow("成绩统计图");
42             chart.pack();// 以合适的大小显示
43             chart.setVisible(true);
44 
45         }
46     }
View Code

3.统计成绩通过柱状图显示

 1 public static CategoryDataset createDataset() // 创建柱状图数据集
 2     {
 3 
 4         DefaultCategoryDataset dataset = new DefaultCategoryDataset();
 5 
 6         int i = 0;
 7         for (String str : scores) {
 8             i++;
 9             String[] split = str.split("-----");
10             dataset.addValue(Integer.parseInt(split[1]), "得分", "第" + i + "次");
11         }
12 
13         return dataset;
14     }
15 
16     public static JFreeChart createChart() // 用数据集创建一个图表
17     {
18         JFreeChart chart = ChartFactory.createBarChart("分数统计图", "分数统计", "得分",
19                 createDataset(), PlotOrientation.VERTICAL, false, true, false); // 创建一个JFreeChart
20         
21         chart.setBorderPaint(Color.blue);
22         chart.setBackgroundPaint(Color.lightGray);
23         chart.setTitle(new TextTitle("成绩分析图", FONT));// 可以重新设置标题,
24         CategoryPlot plot = (CategoryPlot) chart.getPlot();// 获得图标中间部分,即plot
25         plot.setDomainCrosshairPaint(Color.orange);
26         CategoryAxis categoryAxis = plot.getDomainAxis();// 获得横坐标
27         categoryAxis.setLabelFont(FONT);// 设置横坐标字体
28         categoryAxis.setTickLabelFont(FONT); // x轴下标
29         categoryAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45);// 分类标签以45度倾斜
30         ValueAxis rangeAxis = plot.getRangeAxis();// 获取柱状
31         rangeAxis.setLabelFont(FONT); // Y轴标题
32         
33         // plot.setBackgroundPaint(Color.orange);//图片背景
34         
35 
36         return chart;
37     }
38 
39     public static JPanel createPanel() {
40         JFreeChart chart = createChart();
41         return new ChartPanel(chart); // 将chart对象放入Panel面板中去,ChartPanel类已继承Jpanel
42     }
View Code

四.运行结果

登录界面:admin ,密码:123456;

 

 

 

 

五、PSP展示

PSP2.1任务内容计划完成的时间(min)实际完成需要的时间(min)
PLanning 计划 60 100
Estimate 估计这个任务需要多少时间,并规划大致工作步骤 60 60
Developmet 开发 480 600
Analysis 需求分析(包括学习新技术) 30 45
Design Spec 生成设计文档 10 20
Design Revie 设计复审(和同事审核设计文档) 30 30
Coding Standard 代码规范 20 30
Design 具体设计 60 80
Coding 具体编码 300 300
Code Review 代码复审 30 360
Test 测试(自我测试,修改代码,提交修改) 20 30
Reporting 报告 30 35
Test Report 测试报告 20 20
Size Measurement 计算工作量 5 5
Postmortem & Process Improvement Plan 事后总结,并提出过程改机计划 30 35
posted @ 2018-04-03 23:13  花开~半夏  阅读(451)  评论(3编辑  收藏  举报