注释什么的太麻烦了,随便写了点注释,
[AppleScript] 纯文本查看 复制代码 import java.util.HashMap;
import java.util.Scanner;
import java.util.Set;
public class Exam {
// 属性设定
private String name;
private Integer id;
private int score;
// 试卷设定
private HashMap<String, String> test = new HashMap<>();
/**
* 主线程开始考试
*
* @param args
*/
public static void main(String[] args) {
beginExam();
}
/**
* 考试开始,创建试卷类
*/
private static void beginExam() {
Scanner sc = new Scanner(System.in);
System.out.println("请输入学生姓名,学号");
String get = sc.nextLine();
String[] mas = get.split(",");
new Exam(mas[0], Integer.parseInt(mas[1])).examIng();
}
/**
* 开始答题
*/
public void examIng() {
Scanner sc = new Scanner(System.in);
Set<String> t = test.keySet();
for (String str : t) {
System.out.println(str);
System.out.println("你的选择:");
String ans = sc.next();
if (ans.toUpperCase().equals(test.get(str))) {
score += 2;
System.out.println("错误");
}
}
System.out.println("总分是:" + test.size() * 2 + "分\r\n" + "你的得分是:"
+ score);
}
/**
* 初始化属性,设定试卷内容
*
* @param name
* @param id
*/
public Exam(String name, Integer id) {
super();
this.name = name;
this.id = id;
setTest();
}
/**
* 试卷内容设定
*/
private void setTest() {
test.put("题1:..........", "A");
test.put("题2:..........", "C,D");
test.put("题3:..........", "A,B");
test.put("题4:..........", "D");
test.put("题5:..........", "D");
test.put("题6:..........", "B");
test.put("题7:..........", "A");
}
}
|