diff --git a/src/main/java/Math/MathPool.java b/src/main/java/Math/MathPool.java new file mode 100644 index 0000000000..569e083634 --- /dev/null +++ b/src/main/java/Math/MathPool.java @@ -0,0 +1,34 @@ +package Math; +import java.util.Random; +import java.util.ArrayList; + +public class MathPool { + private ArrayList poolOfQuestions; + private final Random random; + + + public MathPool(){ + random = new Random(); + } + + public void addMathQuestion(String wordProblem, int solution, int difficulty){ + MathQuestion problem = new MathQuestion(wordProblem, solution, difficulty); + poolOfQuestions.add(problem); + } + + public MathQuestion getQuestionByDifficulty(int targetDifficulty){ + ArrayList filteredQuestions = new ArrayList<>(); + for (MathQuestion question : poolOfQuestions) { + if (question.getDifficulty() == targetDifficulty) { + filteredQuestions.add(question); + } + } + if (!filteredQuestions.isEmpty()) { + int index = random.nextInt(filteredQuestions.size()); + return filteredQuestions.get(index); + } else { + return null; + } + } + +} diff --git a/src/main/java/Math/MathQuestion.java b/src/main/java/Math/MathQuestion.java new file mode 100644 index 0000000000..cbdd24a27f --- /dev/null +++ b/src/main/java/Math/MathQuestion.java @@ -0,0 +1,25 @@ +package Math; + +public class MathQuestion { + private String question; + private int answer; + private int difficulty; + + public MathQuestion(String qn, int ans, int diff){ + this.question = qn; + this.answer = ans; + this.difficulty = diff; + } + + public String getQuestion(){ + return question; + } + + public int getDifficulty() { + return difficulty; + } + + public boolean checkAns(int userAns){ + return answer == userAns; + } +}