|
@@ -61,10 +61,7 @@ public class QuestionOptionHelper {
|
|
|
|
|
|
if (numberStr.startsWith("[") && numberStr.endsWith("]")) {
|
|
if (numberStr.startsWith("[") && numberStr.endsWith("]")) {
|
|
// 已经是Json数字数组的新格式数据,直接解析并返回
|
|
// 已经是Json数字数组的新格式数据,直接解析并返回
|
|
- String[] values = numberStr
|
|
|
|
- .replace("[", "")
|
|
|
|
- .replace("]", "")
|
|
|
|
- .split(",");
|
|
|
|
|
|
+ String[] values = numberStr.replace("[", "").replace("]", "").split(",");
|
|
|
|
|
|
for (String x : values) {
|
|
for (String x : values) {
|
|
if (StringUtils.isBlank(x)) {
|
|
if (StringUtils.isBlank(x)) {
|
|
@@ -87,6 +84,8 @@ public class QuestionOptionHelper {
|
|
if (String.valueOf(c).matches("[0-9]")) {
|
|
if (String.valueOf(c).matches("[0-9]")) {
|
|
// 只处理0-9之间的数字
|
|
// 只处理0-9之间的数字
|
|
numbers.add(c - 48);
|
|
numbers.add(c - 48);
|
|
|
|
+ } else {
|
|
|
|
+ // 忽略其它字符
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -107,18 +106,35 @@ public class QuestionOptionHelper {
|
|
* 比较正确答案和学生作答答案是否一致(兼容新、旧格式数据)
|
|
* 比较正确答案和学生作答答案是否一致(兼容新、旧格式数据)
|
|
*/
|
|
*/
|
|
public static boolean isEqualAnswer(String correctAnswer, String studentAnswer) {
|
|
public static boolean isEqualAnswer(String correctAnswer, String studentAnswer) {
|
|
|
|
+ if (StringUtils.isEmpty(correctAnswer) || StringUtils.isEmpty(studentAnswer)) {
|
|
|
|
+ // 空正确答案 或 空作答答案,则判为“作答不正确”
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (studentAnswer.equals(correctAnswer)) {
|
|
|
|
+ // 作答答案与正确答案完全一致,则直接判为“作答正确”
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 兼容判断题情况(true,false)
|
|
|
|
+ correctAnswer = correctAnswer.replace("true", "1").replace("false", "0");
|
|
|
|
+ studentAnswer = studentAnswer.replace("true", "1").replace("false", "0");
|
|
|
|
+
|
|
List<Integer> correctAnswers = parseNumberOptions(correctAnswer);
|
|
List<Integer> correctAnswers = parseNumberOptions(correctAnswer);
|
|
List<Integer> studentAnswers = parseNumberOptions(studentAnswer);
|
|
List<Integer> studentAnswers = parseNumberOptions(studentAnswer);
|
|
return CollectionUtils.isEqualCollection(correctAnswers, studentAnswers);
|
|
return CollectionUtils.isEqualCollection(correctAnswers, studentAnswers);
|
|
}
|
|
}
|
|
|
|
|
|
/*public static void main(String[] args) {
|
|
/*public static void main(String[] args) {
|
|
- System.out.println(parseNumbers("987654321 "));
|
|
|
|
- System.out.println(parseNumbers("[3,22,1 ]"));
|
|
|
|
|
|
+ System.out.println(isEqualAnswer("", ""));//false
|
|
|
|
+ System.out.println(isEqualAnswer("", "123"));
|
|
|
|
+ System.out.println(isEqualAnswer("123", ""));
|
|
|
|
|
|
System.out.println(isEqualAnswer("123", "321"));
|
|
System.out.println(isEqualAnswer("123", "321"));
|
|
System.out.println(isEqualAnswer("123", "[3,2,1]"));
|
|
System.out.println(isEqualAnswer("123", "[3,2,1]"));
|
|
- System.out.println(isEqualAnswer("123", "[321]"));
|
|
|
|
|
|
+ System.out.println(isEqualAnswer("123", "[321]"));//false
|
|
|
|
+ System.out.println(isEqualAnswer("true", "true"));
|
|
|
|
+ System.out.println(isEqualAnswer("true", "false"));
|
|
}*/
|
|
}*/
|
|
|
|
|
|
}
|
|
}
|