iT邦幫忙

2026 iThome 鐵人賽

DAY 29
0

本日進度:

  1. 寫了一個 RTEnterSystem.java 檔案
package Project1.Allcode;
import java.util.Scanner;

public class RTEnterExam {
    public static void main(String[] args) {
        Scanner cho = new Scanner(System.in);

        while (true) {
            System.out.println(" 呼吸治療師國考答題系統 ");
            System.out.println(" 1. 開始測驗 ");
            System.out.println(" 2. 離開系統 ");
            System.out.print(" 請輸入選項: ");

            int choice = cho.nextInt();
            System.out.println();

            if (choice == 1) {
                int subject;

                while (true) {
                    System.out.println(" 請選擇科目 ");
                    System.out.println(" 1. 藥理學 ");
                    System.out.println(" 2. 呼吸器原理及應用 ");
                    System.out.print(" 請輸入科目(number): ");

                    subject = cho.nextInt();
                    System.out.println();

                    if (subject == 1 || subject == 2) {
                        break;
                    } else {
                        System.out.println(" 輸入錯誤,請重新輸入 ");
                        System.out.println();
                    }
                }

                int year;

                while (true) {
                    System.out.println(" 請選擇考試年度 ");
                    System.out.println(" 1. 115 年 ");
                    System.out.println(" 2. 114 年 ");
                    System.out.println(" 3. 113 年 ");
                    System.out.print(" 請輸入年度(number): ");

                    year = cho.nextInt();
                    System.out.println();

                    if (year >= 1 && year <= 3) {
                        break;
                    } else {
                        System.out.println(" 輸入錯誤,請重新輸入 ");
                        System.out.println();
                    }
                }

                int examYear = 116 - year;

                if (subject == 1) {
                    System.out.println(" 已選擇藥理學 " + examYear + " 年考題 ");
                    System.out.println();
                } else if (subject == 2) {
                    System.out.println(" 已選擇呼吸器原理及應用 " + examYear + " 年考題 ");
                    System.out.println();
                
                    QuizSystem quizSystem = new QuizSystem();
                    quizSystem.startQuiz(examYear);
                }

            } else if (choice == 2) {
                System.out.println(" 離開系統 ");
                System.out.println();
                break;

            } else {
                System.out.println(" 輸入錯誤,請重新輸入 ");
                System.out.println();
            }
        }

        cho.close();
    }
}
  1. 寫了 QuizSystem.java 放答題相關程式
package Project1.Allcode;
import java.util.Scanner;
import Project1.Ventilation.Vtest_115.Vtest_115;
import java.util.ArrayList;
import java.util.Collections;

public class QuizSystem {
    public void startQuiz(int examYear){
        System.out.println(" 開始測驗 ");
        Scanner input = new Scanner(System.in);
        int mode;

        while(true){
            System.out.println(" 選擇批改模式 ");
            System.out.println(" 1. 逐題批改 ");
            System.out.println(" 2. 全部作答完再批改 ");
            System.out.print(" 請輸入選項: ");

            if(!input.hasNextInt()){
                System.out.println(" 輸入錯誤,請重新輸入 ");
                input.next();
                continue;
            }

            mode = input.nextInt();
            if(mode == 1 || mode == 2){
                break;
            } else {
                System.out.println(" 輸入錯誤,請重新輸入 ");
            }
        }

        int correct = 0;
        int wrong = 0;
        java.util.List<Question> wrongQuestions = new java.util.ArrayList<>();
        java.util.List<Character> wrongAnswers = new java.util.ArrayList<>();
        java.util.List<Integer> wrongNumbers = new java.util.ArrayList<>();

        if(examYear == 115){
            ArrayList<Question> questionList = new ArrayList<>(java.util.Arrays.asList(Vtest_115.questions));
            Collections.shuffle(questionList);
            int questionNumber = 1;

            for(Question q : questionList){
                System.out.println(questionNumber + ". " + q.question);
                for(int i = 0; i < q.options.length; i++){
                    System.out.println(" (" + (char)('A' + i) + ") " + q.options[i]);
                }

                char answer = ' ';
                while(true){
                    System.out.print(" 請輸入答案: ");
                    String userAnswer = input.next().toUpperCase();
                    System.out.println();

                    if(userAnswer.length() == 1 && userAnswer.charAt(0) >= 'A' && userAnswer.charAt(0) <= 'D'){
                        answer = userAnswer.charAt(0);
                        break;
                    } else {
                        System.out.println(" 輸入錯誤,請重新輸入 ");
                    }
                }

                if(answer == q.answer){
                    correct++;
                    if(mode == 1){
                        System.out.println();
                        System.out.println(" 答對了! ");
                        System.out.println();
                    }
                } else {
                    wrong++;
                    wrongQuestions.add(q);
                    wrongAnswers.add(answer);
                    wrongNumbers.add(questionNumber);
                    if(mode == 1){
                        System.out.println(" 答錯了! " );
                        System.out.println();
                        System.out.println(" 正確答案:" + q.answer);
                        System.out.println(" 解析:");
                        System.out.println(q.explanation);
                        System.out.println();
                    }
                }
                questionNumber++;
            }
        } else {
            System.out.println(" 尚未提供此年度的考題 ");
        }
        System.out.println(" 測驗結果:");
        System.out.println(" 答對題數:" + correct);
        System.out.println(" 答錯題數:" + wrong);

        int total = correct + wrong;

        if(total > 0){
            double accuracy = (double) correct / total * 100;
            System.out.printf(" 正確率:%.2f%%\n", accuracy);
            System.out.println();
        }

        if(mode == 1){
            System.out.println(" 錯誤題目解析: ");
        }else if(mode == 2){
            System.out.println(" 錯誤題目解析: ");
        }
        
        if(wrongQuestions.isEmpty()){
            System.out.println(" 無錯誤題目 ");
        } else {
            for(int i = 0; i < wrongQuestions.size(); i++){
                Question q = wrongQuestions.get(i);
                System.out.println(wrongNumbers.get(i) + " . " +q.question);
                System.out.println(" 你的答案:" + wrongAnswers.get(i));
                System.out.println(" 正確答案:" + q.answer);
                System.out.println(" 解析:" + q.explanation);
                System.out.println();
            }
        }
        System.out.println();
        System.out.println(" 測驗結束,即將返回主選單 ");
        System.out.println();
        input.close();
    }
}
  1. 寫了 Vtest_115.java 放題目(未放置完成,先以兩題做示範)
  2. 寫了 Question.java,定義一道考題應該包含哪些資料、如何建立一道考題
package Project1.Allcode;

public class Question {
    String question;
    String[] options;
    char answer;
    String explanation;

    public Question(String question, String[] options, char answer, String explanation) {
        this.question = question;
        this.options = options;
        this.answer = answer;
        this.explanation = explanation;
    }
}

明日目標:

  1. 115 年度考題建置
  2. 還需處理:錯題重練、歷史成績、作答進度保存、計時
  3. 非必要:考試範圍分類、建置 114 年度考題
  4. debug
  5. 某些錯誤情境處理

上一篇
Day 28:成果(1)
系列文
從零開始學程式語言:Java 新手修煉記 共 29 篇
圖片
  熱門推薦
圖片
{{ item.channelVendor }} | {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言