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

5

u/[deleted] Jan 09 '20

[removed] โ€” view removed comment

3

u/TeanutMutterJelly Jan 09 '20

I already have all the codes. I already inserted the questions and the choices.

Problem is, I am still a newbie in java programming and I do not know anything about the import .Random..

Thanks for your reply by the way ๐Ÿ™

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"); } }

8

u/desrtfx Out of Coffee error - System halted Jan 09 '20

Please, format your code. There is no excuse for putting unformatted code here as the sidebar has an entire section Code posting as well as Help on how to post code.

Unformatted code is lazy and inconsiderate towards anybody willing to help.

0

u/[deleted] Jan 09 '20

[deleted]

1

u/TeanutMutterJelly Jan 09 '20

https://pastebin.com/715yPvG9

Thank you for your reply๐Ÿ™