Commit cffa3ad0 authored by Ethan Liang's avatar Ethan Liang
Browse files

randomize answers

parent 0b6b7fc1
Loading
Loading
Loading
Loading
+32 −27
Original line number Diff line number Diff line
@@ -177,33 +177,16 @@ public class ChalkActivity extends AppCompatActivity implements View.OnClickList

        questionTextView.setText(ChalkQuestionAnswer.question[currentQuestionIndex]);

        // Randomize orders of choices displayed
        int[] orders = new int[]{0, 1, 2, 3};
        // Randomize orders[]
        Random rand = new Random();

        for (int i = 0; i < orders.length; i++) {
            // Switch i and randomIndexToSwap
            int randomIndexToSwap = rand.nextInt(orders.length);
        int[] randomized = randomizeOrders();

            // temp vars to store element at randomIndex
            int tempOrder = orders[randomIndexToSwap];

            // element at randomIndex is now element at i (2 i duplicates)
            orders[randomIndexToSwap] = orders[i];

            // element at i is now element at randomIndex (via temp vars)
            orders[i] = tempOrder;
        }

        /*ansA.setText(ChalkQuestionAnswer.choices[currentQuestionIndex][orders[0]]);
        ansB.setText(ChalkQuestionAnswer.choices[currentQuestionIndex][orders[1]]);
        ansC.setText(ChalkQuestionAnswer.choices[currentQuestionIndex][orders[2]]);
        ansD.setText(ChalkQuestionAnswer.choices[currentQuestionIndex][orders[3]]);*/
        ansA.setText(ChalkQuestionAnswer.choices[currentQuestionIndex][0]);
        ansA.setText(ChalkQuestionAnswer.choices[currentQuestionIndex][randomized[0]]);
        ansB.setText(ChalkQuestionAnswer.choices[currentQuestionIndex][randomized[1]]);
        ansC.setText(ChalkQuestionAnswer.choices[currentQuestionIndex][randomized[2]]);
        ansD.setText(ChalkQuestionAnswer.choices[currentQuestionIndex][randomized[3]]);
        /*ansA.setText(ChalkQuestionAnswer.choices[currentQuestionIndex][0]);
        ansB.setText(ChalkQuestionAnswer.choices[currentQuestionIndex][1]);
        ansC.setText(ChalkQuestionAnswer.choices[currentQuestionIndex][2]);
        ansD.setText(ChalkQuestionAnswer.choices[currentQuestionIndex][3]);
        ansD.setText(ChalkQuestionAnswer.choices[currentQuestionIndex][3]);*/
    }

    void finishQuiz(){
@@ -220,6 +203,28 @@ public class ChalkActivity extends AppCompatActivity implements View.OnClickList
        finish();
    }

    public int[] randomizeOrders() {
        int[] randomized = { 0, 1, 2, 3 };

        // Randomize orders[]
        Random rand = new Random();

        for (int i = 0; i < randomized.length; i++) {
            // Switch i and randomIndexToSwap
            int randomIndexToSwap = rand.nextInt(randomized.length);

            // temp vars to store element at randomIndex
            int tempOrder = randomized[randomIndexToSwap];

            // element at randomIndex is now element at i (2 i duplicates)
            randomized[randomIndexToSwap] = randomized[i];

            // element at i is now element at randomIndex (via temp vars)
            randomized[i] = tempOrder;
        }

        return randomized;
    }
    protected void onPause() {
        super.onPause();
        backgroundMusic.stop();
+8 −8
Original line number Diff line number Diff line
@@ -10,16 +10,16 @@ public class ChalkQuestionAnswer {
    };

    public static String[][] choices = {
        {"501B50797001", "501C50767001", "501C50757001", "501B50897001"},
        {"C0017001C0017001", "B0017001D0017001", "C0016001C0016001", "B0017001D0018001"},
        {"5000504a50947040", "5000504b50957040", "5000504a50947040", "5000504b50947040"},
        {"c000c0014042d7fc", "c000d0024042d7fc", "c000d0014042d7fb", "c000c0014042d7fc"},
        {"/501B50797001", "501C50767001", "501C50757001", "501B50897001"},
        {"/C0017001C0017001", "B0017001D0017001", "C0016001C0016001", "B0017001D0018001"},
        {"/5000504a50947040", "5000504b50957040", "5000504a50947040", "5000504b50947040"},
        {"/c000c0014042d7fc", "c000d0024042d7fc", "c000d0014042d7fb", "c000c0014042d7fc"},
    };

    public static String[] correctAnswers = {
        "501B50797001",
        "C0017001C0017001",
        "5000504a50947040",
        "c000c0014042d7fc"
        "/501B50797001",
        "/C0017001C0017001",
        "/5000504a50947040",
        "/c000c0014042d7fc"
    };
}