From 50784178b371185317fd58e3691e978acafcade0 Mon Sep 17 00:00:00 2001 From: Friederike von Gruben Date: Thu, 2 Feb 2023 00:26:42 +0100 Subject: [PATCH] Update QuizCommand.java Getting userinput and checking whether answer is correct --- src/main/java/org/bitbiome/commands/QuizCommand.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/main/java/org/bitbiome/commands/QuizCommand.java b/src/main/java/org/bitbiome/commands/QuizCommand.java index 3d10aea..241917d 100644 --- a/src/main/java/org/bitbiome/commands/QuizCommand.java +++ b/src/main/java/org/bitbiome/commands/QuizCommand.java @@ -30,7 +30,17 @@ public class QuizCommand implements CommandAPI { String antwort = antworten.getString(i); System.out.println(i + 1 + ". " + antwort); } + Scanner quizScanner = new Scanner(System.in); + int eingabe = quizScanner.nextInt(); + String korrekteAntwort = frage.getString("korrekteAntwort"); + + if (antworten.getString(eingabe - 1).equalsIgnoreCase(korrekteAntwort)) { + System.out.println("Richtige Antwort!\n"); + } else { + System.out.println("Leider falsch... Richtig ist: " + korrekteAntwort + "\n"); + } + System.out.println("Das Quiz ist vorbei."); } }