Exam.java
public class Exam {
public static void main(String[] args) {
ExamView EV = new ExamView() ;
EV.testExam();
}
}
ExamView.java
import java.util.Scanner;
public class ExamView {
private ItemService IS = new ItemService() ;
private char[] answer ;
public ExamView(){
answer = new char[IS.TOTAL_ITEMS] ;
for (int i=0; i < answer.length; i++){
answer[i] = ' ' ;
}
}
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 ;
}
public void displayItem(int no){
System.out.println(IS.getItem(no).getQuestion());
String[] options = IS.getItem(no).getOptions() ;
for (String option : options){
System.out.println(option);
}
}
public void testExam(){
int curItem = 1 ;
displayWelcomInfo() ;
while (true){
displayItem(curItem);
System.out.println("请选择正确答案(p-上一题 n-下一题)");
char key = getUserAction() ;
switch (key){
case 'A':
case 'B':
case 'C':
case 'D':