Commit 3aea6a4d authored by Ethan Liang's avatar Ethan Liang
Browse files

create chalk qusetions; randomize chalk questions order; update quiz layout

parent e1b504ec
Loading
Loading
Loading
Loading
+45 −15
Original line number Diff line number Diff line
package com.example.game2d;
import java.util.Random;

public class ChalkQuestionAnswer {
    public static void shuffleQuestions() {

    public static String question[] =  {
        "Question 1",
                "Question 2",
                "Question 3",
                "Question 4"
        Random rand = new Random();

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

            int randomIndexToSwap = rand.nextInt(question.length);

            // temp vars to store element at randomIndex
            String tempQuestion = question[randomIndexToSwap];
            String[] tempChoices = choices[randomIndexToSwap];
            String tempAnswers = correctAnswers[randomIndexToSwap];

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

            // element at i is now element at randomIndex (via temp vars)
            question[i] = tempQuestion;
            choices[i] = tempChoices;
            correctAnswers[i] = tempAnswers;
        }
    }

    public static String[] question =  {
        "mov R0, 27\nmov R1, 57\nmov [R0], R1",
        "inc R1 ; mov [R0], R1\ninc R1 ; mov [R0], R1",
        "mov R0, 1 ; mov R1, 1\nmov R2, 48 ; mov [R1], R0",
        "loop: inc R0 ; inc R1\ncmp R1, R2 ; jne -4"
    };

    public static String choices[][] = {
        {"Correct", "Choice 2", "Choice 3", "Choice 4"},
        {"Choice 1", "Correct", "Choice 3", "Choice 4"},
        {"Choice 1", "Choice 2", "Correct", "Choice 4"},
        {"Choice 1", "Choice 2", "Choice 3", "Correct"},
    public static String[][] choices = {
        {"501B507970010000", "501C507570010000", "501C50757001", "501B50797001"},
        {"C0017001C00170010000", "B0017001D00170010000", "C0017001C0017001", "B0017001D0018001"},
        {"5000504b509470400000", "5000504a509470400000", "5000504a50947040", "5000504b50947040"},
        {"c000c0014042d7fc0000", "c000d0014042d7fc", "c000d0014042d7fb0000", "c000c0014042d7fc"},
    };

    public static String correctAnswers[] = {
        "Correct",
                "Correct",
                "Correct",
                "Correct"
    public static String[] correctAnswers = {
        "501B507970010000",
        "C0017001C00170010000",
        "5000504a509470400000",
        "c000c0014042d7fc0000"
    };

    public static void main(String[] args) {
        shuffleQuestions();
    }

}
+15 −11
Original line number Diff line number Diff line
@@ -48,16 +48,17 @@
        android:textSize="24dp"
        android:textStyle="bold" />


    <TextView
        android:id="@+id/question"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/questionHeader"
        android:layout_marginStart="20dp"
        android:layout_marginTop="56dp"
        android:layout_marginTop="0dp"
        android:layout_marginEnd="20dp"
        android:layout_marginBottom="20dp"
        android:text="This will be the question"
        android:layout_marginBottom="0dp"
        android:text="fjakfjsakl\nsdf\nsdf"
        android:textAlignment="center"
        android:textColor="@color/white"
        android:textSize="35dp"
@@ -70,51 +71,54 @@
        android:layout_above="@+id/submit_btn"
        android:columnCount="2"
        android:rowCount="2"

        >

        <Button
            android:id="@+id/ans_B"
            android:layout_width="wrap_content"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_rowWeight="1"
            android:layout_columnWeight="1"
            android:layout_gravity="fill"
            android:layout_marginRight="5dp"
            android:layout_marginBottom="0dp"
            android:backgroundTint="@color/white"
            android:text="Ans A"
            android:text="501B507970010000"
            android:textColor="@color/black" />

        <Button
            android:id="@+id/ans_A"
            android:layout_width="wrap_content"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_rowWeight="1"
            android:layout_columnWeight="1"
            android:layout_gravity="fill"
            android:layout_marginLeft="5dp"
            android:layout_marginBottom="0dp"
            android:backgroundTint="@color/white"
            android:text="Ans A"
            android:text="50170010000"
            android:textColor="@color/black" />

        <Button
            android:id="@+id/ans_C"
            android:layout_width="wrap_content"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_rowWeight="1"
            android:layout_columnWeight="1"
            android:layout_marginRight="5dp"
            android:layout_gravity="fill"
            android:layout_marginTop="0dp"
            android:layout_marginRight="5dp"
            android:backgroundTint="@color/white"
            android:text="Ans A"
            android:textColor="@color/black" />

        <Button
            android:id="@+id/ans_D"
            android:layout_width="wrap_content"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_rowWeight="1"
            android:layout_columnWeight="1"
            android:layout_gravity="fill"
            android:layout_marginLeft="5dp"
            android:layout_marginTop="0dp"
            android:backgroundTint="@color/white"