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

二、项目报告

1、需求分析

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

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

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

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

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

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

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

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

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

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

3.设计实现

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

三.核心代码展示

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

相关文章:

猜你喜欢
  • 2021-08-10
  • 2021-05-23
  • 2021-07-28
  • 2021-08-11
  • 2021-05-23
相关资源
相似解决方案