Untitled
unknown
plain_text
7 months ago
2.5 kB
2
Indexable
Never
import java.util.Scanner; // USER DEFINED EXCEPTIONS class onlyABC extends Exception { onlyABC() { super("ABC LANG OK!!!!!!!! TRY AGAIN"); } } class noNumAndSpecChar extends Exception { noNumAndSpecChar() { super("BAWAL NUMBER AT IBANG CHARACTER. TRY AGAIN"); } } class emptySpace extends Exception { emptySpace() { super("WALA KANG SINULAT. TRY AGAIN"); } } // MAIN CLASS public class QuizBee { public static void main(String[] args) { Scanner bhie = new Scanner(System.in); double totalScr = 0; // QUESTIONS String[][] qs = { {"(QUESTION) \nA. \nB. \nC.", "A"}, {"(QUESTION) \nA. \nB. \nC.", "B"}, {"(QUESTION) \nA. \nB. \nC.", "C"}, {"(QUESTION) \nA. \nB. \nC.", "A"}, {"(QUESTION) \nA. \nB. \nC.", "C"}, {"(QUESTION) \nA. \nB. \nC.", "A"}, {"(QUESTION) \nA. \nB. \nC.", "A"}, {"(QUESTION) \nA. \nB. \nC.", "C"}, {"(QUESTION) \nA. \nB. \nC.", "B"}, {"(QUESTION) \nA. \nB. \nC.", "B"}, }; // OPENING System.out.println("Are you [REDACTED] quiz \n(my lawyer advised me not to complete the sentence)"); System.out.println("Type the letter of your answer ^_______^ \n(A, B, or C)"); // LOOP FOR QNA for (int i = 0; i < qs.length; i++) { try { System.out.println((i + 1) + ".) " + qs[i][0]); String answer = bhie.nextLine().toUpperCase(); if (answer.isEmpty()) { throw new emptySpace(); } else if (!answer.equals("A") && !answer.equals("B") && !answer.equals("C")) { throw new onlyABC(); } else if (answer.matches(".*\\d.*")) { throw new noNumAndSpecChar(); } if (answer.equalsIgnoreCase(qs[i][1])) { totalScr += 10; } } catch (emptySpace ES) { System.out.println(ES.getMessage()); i--; } catch (onlyABC ABC) { System.out.println(ABC.getMessage()); i--; } catch (noNumAndSpecChar NSC) { System.out.println(NSC.getMessage()); i--; } } System.out.println("Total Score: " + totalScr); } }
Leave a Comment