Exam.java
public class Exam {
public static void main(String[] args) {
//测试一:
// ItemService itemService = new ItemService();
// List<String> list = itemService.readTextFile("Items.txt");
// for(String s : list){
// System.out.println(s);
// }
//测试二:
// ItemService itemService = new ItemService();
// Item item = itemService.getItem(1);
// System.out.println(item);
ExamView examView = new ExamView();
examView.enterMainMenu();
}
}
ExamView.java
import java.util.Scanner;
public class ExamView {
private ItemService itemService = new ItemService();
private char[] answer;
public ExamView() {
answer = new char[itemService.TOTAL_ITEMS];
for (int i = 0; i < answer.length; i++) {
answer[i] = ' ';
}
}
public void enterMainMenu() {
while (true) {
displayMainMenu();
char key = getUserAction();
switch (key) {
case '1':
testExam();
break;
case '2':
reviewLastExam();
break;
case '3':
if (confirmEnd("确认是否退出(Y/N):"))
return;
}
}
}
/**
* 获取用户输入的指定字符
* @return
*/
public char getUserAction() {
char[] validKey = {
'1', '2', '3', 'A', 'B', 'C', 'D', 'F', 'N', 'P',
'Y' };
char key = 0;
Scanner scanner = new Scanner(System.in);
while (scanner.hasNext()) {
String str = scanner.next();
if (str.length() != 1)
continue;
str = str.toUpperCase();
key = str.charAt(0);
for (char k : validKey) {
if (k == key) {
return key;
}
}
}
return key;
}
/**
* 显示指定的考题内容
* @param no
*/
public void displayItem(int no) {
if (no < 1 || no > itemService.TOTAL_ITEMS)
return;
Item item = itemService.getItem(no);
System