Skip to content

Commit

Permalink
Merge pull request #16 from B1G-SAM/Math
Browse files Browse the repository at this point in the history
Add Math package
  • Loading branch information
B1G-SAM committed Mar 18, 2024
2 parents c28a224 + 49fd508 commit c09c893
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
34 changes: 34 additions & 0 deletions src/main/java/Math/MathPool.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package Math;
import java.util.Random;
import java.util.ArrayList;

public class MathPool {
private ArrayList<MathQuestion> 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<MathQuestion> 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;
}
}

}
25 changes: 25 additions & 0 deletions src/main/java/Math/MathQuestion.java
Original file line number Diff line number Diff line change
@@ -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;
}
}

0 comments on commit c09c893

Please sign in to comment.