本日進度:
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();
}
}
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();
}
}
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;
}
}
明日目標: