本帖最后由 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(",")[i]);
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[i])) {
return false;
}
}
return true;
}
}
|