单机考试管理软件(9)

在这里插入图片描述
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
  • 2
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值