From 7dba1035be4862623dddd08c609025c352b76597 Mon Sep 17 00:00:00 2001 From: AlisaLinUwU Date: Sun, 26 Jan 2025 11:26:58 +0500 Subject: Initialize --- src/Test.java | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 src/Test.java (limited to 'src/Test.java') diff --git a/src/Test.java b/src/Test.java new file mode 100644 index 0000000..3336199 --- /dev/null +++ b/src/Test.java @@ -0,0 +1,53 @@ +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; + +public class Test extends Question { + private final ArrayList labels = new ArrayList<>(); + private String[] options; + private int numOfOptions; + + public Test() { + } + + public Test(String description, String answer, String[] options) { + super(description, answer); + setOptions(options); + } + + public String getOptionAt(int index) { + return options[index]; + } + + public void setOptions(String[] options) { + this.options = options; + numOfOptions = options.length; + for (int i = 0; i < numOfOptions; i++) { + labels.add((char) (65 + i)); + } + } + + public int getNumOfOptions() { + return numOfOptions; + } + + public boolean isCorrectAnswer(char label) { + return options[label - 65].equals(getAnswer()); + } + + public void shuffleOptions() { + Collections.shuffle(Arrays.asList(options)); + } + + @Override + public String toString() { + StringBuilder information = new StringBuilder(); + + information.append(String.format("%s", getDescription())); + for (int i = 0; i < numOfOptions; i++) { + information.append(String.format("\n%s) %s", labels.get(i), options[i])); + } + + return information.toString(); + } +} -- cgit v1.2.3