黑马程序员技术交流社区

标题: 模拟考试评分 [打印本页]

作者: yu244934256    时间: 2016-10-7 00:29
标题: 模拟考试评分
本帖最后由 yu244934256 于 2016-10-7 22:25 编辑

经过2次考试,发现可以自己实现模拟考试评分功能,经过半小时的编写,基本可以用了,没有处理异常,当你的格式不正确的时候没有捕获异常,你们可以试着完善一下
[AppleScript] 纯文本查看 复制代码
public class Day38_交卷 {

/**
* @desc 模拟交卷 本套题共40道不定项选择题,其中单选30道,多选10道。单选2分/题,多选4分/题。多选题不全对半分,全对满分。
*
* @author purity 2016-10-6下午5:30:00
*/
public static void main(String[] args) {
String standardFileName = "Java_IO知识测试__A卷标准答案.txt";
String submitFileName = "余才华.txt";
int score = getScore(getStandardSolution(submitFileName), getStandardSolution(standardFileName));
submitFileName = submitFileName.substring(0, submitFileName.lastIndexOf("."));
if (score < 60) {
System.out.println(submitFileName + "分数为:" + score + " 革命尚未成功,同志仍需努力");
} else if (score < 85) {
System.out.println(submitFileName + "分数为:" + score + " 基本满足市场需求");
} else if (score < 101) {
System.out.println(submitFileName + "分数为:" + score + " 有钱途哦");
}
}

public static TreeMap<Integer, String> getStandardSolution(String fileName) {
TreeMap<Integer, String> tm = new TreeMap<>();
BufferedReader br = null;
try {
br = new BufferedReader(new FileReader(fileName));
String line = "";
int index = 1;
int row = 0;
while ((line = br.readLine()) != null) {
row++;
try {
for (int i = 0; i < 5; i++) {
tm.put(index, line.split(":")[1].split(","));
index++;
}

} catch (ArrayIndexOutOfBoundsException e) {
System.out.println("请检查第" + row + "行");
System.exit(0); //正常结束JVM运行
}
}
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
br.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return tm;
}

public static int getScore(TreeMap<Integer, String> submit, TreeMap<Integer, String> standard) {
int score = 0;
for (int i = 1; i <= standard.size(); i++) {
if (standard.get(i).length() == 1) { // 1.先判断单选
if (standard.get(i).equals(submit.get(i))) {
score += 2;
}
} else if (standard.get(i).length() == submit.get(i).length()) { // 2.多选全对
if (isExits(standard.get(i), submit.get(i))) {
score += 4;
}
} else if (standard.get(i).length() > submit.get(i).length()) { // 3.半对
if (isExits(standard.get(i), submit.get(i))) {
score += 2;
}
}
}
return score;
}

public static boolean isExits(String a, String b) {
char[] arr2 = b.toCharArray();
for (int i = 0; i < arr2.length; i++) {
if (!a.contains("" + arr2)) {
return false;
}
}
return true;
}

}


作者: 喝咖啡的玉米    时间: 2016-10-7 17:58
可以的,挺有意思的
作者: q1w2e3r4    时间: 2016-10-7 20:05
答案abc,我填cba也不算我错吧
作者: Zzh94520    时间: 2016-10-7 21:50
6666666666666
作者: 暮雨微凉    时间: 2016-10-7 21:58
66666666挺有意思的
作者: yu244934256    时间: 2016-10-7 22:15
q1w2e3r4 发表于 2016-10-7 20:05
答案abc,我填cba也不算我错吧

这个问题,我已修改,我今天也发现这个问题了
作者: 刘野    时间: 2016-10-7 22:44
赞一个..




欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2