Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I would probably start by sorting the questions after the requirement, implement different sorting algorithms for the different levels (putting the most relevant questions for the current difficulty level first). Then it is just to pick questions starting from the beginning of the list.</p> <p>Something like this: </p> <pre><code>static final int[] easy = {1,2,3,4,5,6,7}; static final int[] medium = {3,4,5,6,7,8}; static final int[] hard = {4,5,6,7,8,9,10}; public static List&lt;Question&gt; getQuestions(List&lt;Question&gt; availableQuestions, int quizDifficulty, int numberOfQuestion){ if(quizDifficulty == 0) // Easy Collections.sort(availableQuestions, new CompareQuestion(easy)); else if(quizDifficulty == 2) // Hard Collections.sort(availableQuestions, new CompareQuestion(hard)); else if(quizDifficulty == 1) // Normal Collections.sort(availableQuestions, new CompareQuestion(medium)); int questions = availableQuestions.size(); return availableQuestions.subList(0, numberOfQuestion &lt;= questions ? numberOfQuestion : questions); } static class CompareQuestion implements Comparator&lt;Question&gt;{ final int[] compareList; public CompareQuestion(int[] compareList){ this.compareList = compareList; } @Override public int compare(Question q1, Question q2) { boolean o1wanted = inList(q1.difficulty, compareList); boolean o2wanted = inList(q2.difficulty, compareList); if(o1wanted &amp;&amp; o2wanted) return 0; if(o1wanted &amp;&amp; !o2wanted) return -1; return 1; } public boolean inList(int a, int[] list){ for(int i : list) if(a == i) return true; return false; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload