r/javahelp • • Jan 09 '20

Homework I need you help

I am a Senior High student and was assigned to program a quiz in java. But my professor wants the questions to be randomized.

Unfortunately, i don't know how to execute it

Help me please

👇here's the link

The Code

3 Upvotes

16 comments sorted by

View all comments

Show parent comments

2

u/[deleted] Jan 09 '20

[removed] — view removed comment

3

u/TeanutMutterJelly Jan 09 '20

package quizbee; import java.util.InputMismatchException; import java.util.Scanner;

public class Quizbee extends Exception { public static void main (String[] args) throws QuizBee{ Scanner scan = new Scanner (System.in); String[] questions = {"1. Question","2. Question"}"; String[] choices = {"A. Choice\tB. Choice\tC.Choice"}; String[] answerKey = {"Answer","Answer"}; String ans = " "; int score = 0;

System.out.println ("TakeTest Quiz") System.out.println("Choose the letter of the correct answer);

for (int x=0;x<questions.length;x++) { System.out.println("\n"+questions[x]); System.out.println("\n"+choices[x]); System.out.println("\nAnswer: ");

try { ans = scan.nextLine(); ans = ans.toUpperCase(); if (ans.trim().equalsIgnoreCase(answerKey[x].substring(0.1))){ System.out.println("\nYou got it Right!") score++ }

else if (ans.equalsIgnoreCase("A")|| ans.equalsIgnoreCase("B")||ans.equalsIgnoreCase("C") && !ans.equalsIgnoreCase(answerKey[x].substring(0.1))){ System.out.println("\nSorry, the correct answer is"+answerKey[x]+"."); } else if {!ans.equalsIgnoreCase(answerKey[x]))){ throw new InputMismatchException(); } else if {ans.equals(" ") { throw new NullPointerException(); } } catch (InputMismatchException e) { System.out.println("Please select a letter from the letters A,B and C"); x--; } catch(NullPointerException e) { System.out.println("Please select a letter from the letters A,B and C"); x--; } } System.out.println("Your score is: " +score+ "10."); } private static Exception InputMismatchException() { throw new UnsupportedOperationException("Not Supported Yet"); } }

0

u/[deleted] Jan 09 '20

[deleted]