Browse Source

refactoring: Outsourced code

Whether the answer is correct or not is outsourced now
remotes/origin/quiz
Friederike von Gruben 2 years ago
parent
commit
34c135d54c
  1. 6
      src/main/java/org/bitbiome/commands/QuizCommand.java

6
src/main/java/org/bitbiome/commands/QuizCommand.java

@ -34,7 +34,7 @@ public class QuizCommand implements CommandAPI {
int eingabe = quizScanner.nextInt();
String korrekteAntwort = frage.getString("korrekteAntwort");
if (antworten.getString(eingabe - 1).equalsIgnoreCase(korrekteAntwort)) {
if (answerIsCorrect(eingabe, korrekteAntwort, antworten)) {
System.out.println("Richtige Antwort!\n");
} else {
System.out.println("Leider falsch... Richtig ist: " + korrekteAntwort + "\n");
@ -42,6 +42,10 @@ public class QuizCommand implements CommandAPI {
System.out.println("Das Quiz ist vorbei.");
}
public static boolean answerIsCorrect(int picked, String answer, JSONArray answers) {
return answers.getString(picked - 1).equalsIgnoreCase(answer);
}
}
Loading…
Cancel
Save