HNU个人项目代码互评
作者:杨雅琨
分析对象:马小梅
一.题目:中小学数学试卷自动生成系统
二.功能及完成情况
功能1:
命令行输入用户名和密码,两者之间用空格隔开(程序预设小学、初中和高中各三个账号,具体见附表),如果用户名和密码都正确,将根据账户类型显示“当前选择为XX出题”,XX为小学、初中和高中三个选项中的一个。否则提示“请输入正确的用户名、密码”,重新输入用户名、密码;
完成情况:
完成情况良好
功能2:
登录后,系统提示“准备生成XX数学题目,请输入生成题目数量(输入-1将退出当前用户,重新登录):”,XX为小学、初中和高中三个选项中的一个,用户输入所需出的卷子的题目数量,系统默认将根据账号类型进行出题。每道题目的操作数在1-5个之间,操作数取值范围为1-100;
完成情况:
完成情况良好
功能3:
题目数量的有效输入范围是“10-30”(含10,30,或-1退出登录),程序根据输入的题目数量生成符合小学、初中和高中难度的题目的卷子(具体要求见附表)。同一个老师的卷子中的题目不能与以前的已生成的卷子中的题目重复(以指定文件夹下存在的文件为准,见5)
完成情况:
符合要求,且经有限次测试无重复现象
功能4:
在登录状态下,如果用户需要切换类型选项,命令行输入“切换为XX”,XX为小学、初中和高中三个选项中的一个,输入项不符合要求时,程序控制台提示“请输入小学、初中和高中三个选项中的一个”;输入正确后,显示“”系统提示“准备生成XX数学题目,请输入生成题目数量”,用户输入所需出的卷子的题目数量,系统新设置的类型进行出题;
完成情况:
完成情况良好
功能5:
生成的题目将以“年-月-日-时-分-秒.txt”的形式保存,每个账号一个文件夹。每道题目有题号,每题之间空一行;
完成情况良好
总体功能完成情况良好,需求全部满足
三.代码结构及规范
类别封装:
public static String createPaper (String account, String type, int num) { PaperCreator.account = account; PaperCreator.type = type; PaperCreator.num = num; String result = "第" + (num + 1) + "题: "; // 表达式 String[] signs = {"+", "-", "*", "/", "^2", "√", "sin", "cos", "tan", "(", ")"}; String question = ""; if(type.equals("小学")) { question = createForPrimary(account, type, signs); // 小学 } else if (type.equals("初中")) { question = createForJunjor(account, type, signs); } else if (type.equals("高中")) { question = createForHigh(account, type,signs); } result += question; // 一道题目 return result; }
public static String createForPrimary (String account, String type, String[] s) { Random r = new Random(); // 小学操作数numb为2到5 int operands_num = r.nextInt(4) + 2; // 存储操作数 String[] operands = new String[operands_num]; for (int i = 0; i < operands_num; i++) { operands[i] = String.valueOf(r.nextInt(100) + 1); } // 表达式 return getExpression(operands_num,operands, s); }
public static String createForJunjor (String account, String type, String[] s) { Random r = new Random(); int operands_num = r.nextInt(5) + 1; // 随机生成符号的数量[1,4] int sign_num = r.nextInt(operands_num) + 1 ; // 平方或根号的数量 String[] operands = new String[operands_num]; boolean[] operans_Flag = new boolean[operands_num] ; for (int i = 0; i < operands_num; i++) { operands[i] = String.valueOf(r.nextInt(100) + 1); } for(int i = 0; i < sign_num; i++) { int pos = r.nextInt(operands_num); // 操作符 if (!operans_Flag[pos]) { if (r.nextBoolean()) { operands[pos] = "√" + operands[pos]; } else { operands[pos] += "^2"; } operans_Flag[pos] = true; } } return getExpression(operands_num,operands,s); }
public static String createForHigh(String account, String type, String[] s) { Random r = new Random(); int operands_num = r.nextInt(5) + 1; // 随机生成符号的数量[1,4] int sign_num = r.nextInt(operands_num) + 1; // sign[4-8]符号的数量 String[] operands = new String[operands_num]; boolean[] operans_Flag = new boolean[operands_num]; for (int i = 0; i < operands_num; i++) { operands[i] = String.valueOf(r.nextInt(100) + 1); } for (int i = 0; i < sign_num; i++) { int pos = r.nextInt(operands_num); if (i == 0) { int num = r.nextInt(3); if (num == 0) { operands[pos] = "sin" + operands[pos]; } else if (num == 1) { operands[pos] = "scos" + operands[pos]; } else if (num == 2) { operands[pos] = "tan" + operands[pos]; } operans_Flag[pos] = true; } else { if (!operans_Flag[pos]) { if (r.nextInt(3) == 0) { if (r.nextInt(2) == 0) { operands[pos] = operands[pos] + "^2"; } else { operands[pos] = "√" + operands[pos]; } } else { if (r.nextInt(3) == 0) { operands[pos] = "sin" + operands[pos]; } else if (r.nextInt(3) == 1) { operands[pos] = "scos" + operands[pos]; } else if (r.nextInt(3) == 2) { operands[pos] = "tan" + operands[pos]; } } operans_Flag[pos] = true; } } } return getExpression(operands_num, operands, s); }
public static String getExpression (int num, String[] operands, String[] s) { Random r = new Random(); // 每个算式有number_num个数字,有number_num-1个运算符号,最多有number_num-2组括号 if (num >= 3 && r.nextBoolean()) { int gap = r.nextInt(num - 2) + 1; int bracketLeft = r.nextInt( num - gap); // 运算符(的位置 int bracketRight = bracketLeft + gap; // 运算符)的位置 operands[bracketLeft] = "(" + operands[bracketLeft]; operands[bracketRight] += ")"; } StringBuilder str = new StringBuilder(operands[0]); for (int i = 0; i < num - 1 ; i++) { str.append(s[r.nextInt(4)]); str.append(operands[i + 1]); } str.append(" = "); str.append("\n"); //换行 return str.toString(); }
public static boolean checkRepeat(String account, String str) { File file = new File(account); // 获取当前老师文件目录下的所有试卷文件列表 File[] files = file.listFiles(); boolean flag = true; // 初始表示未重复 for(File f : files) { try { BufferedReader bf = new BufferedReader( new FileReader(f)); while(true) { String s = bf.readLine(); if (s == null) { break; } String[] expression = s.split(" "); if (expression.length > 1) { if(expression[1].equals(str)) { flag = false; break; } } } bf.close(); } catch (IOException e) { e.printStackTrace(); } if (flag == false) { break; } } return flag; }
代码符合规范,结构设计合理
四.拓展性及接口
创建了画框作为UI界面的拓展
且接口封装良好