Easter Quiz
This is my final Udacity Project for Android Beginner Course:
This is an updated version of the UI
This is the java source code:
package com.catalinwk.android.eastersundayquizz;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.Toast;
import android.widget.EditText;
import android.widget.CheckBox;
import android.widget.RadioButton;
import android.view.*;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
/**
* This method calculates the result of the quiz
*/
public void quizResults(View v){
int score = 0;
//first question
RadioButton radioSelectionQuestion1 = (RadioButton) findViewById(R.id.question_1_a);
if (radioSelectionQuestion1.isChecked())
score += 1;
//second question
CheckBox a = (CheckBox)findViewById(R.id.question_2_a);
CheckBox b = (CheckBox)findViewById(R.id.question_2_b);
CheckBox c = (CheckBox)findViewById(R.id.question_2_c);
if (a.isChecked() & b.isChecked() & c.isChecked())
score += 1;
//third question
RadioButton radioSelectionQuestion3 = (RadioButton) findViewById(R.id.question_3_b);
if (radioSelectionQuestion3.isChecked())
score += 1;
//last question
EditText textField = (EditText)findViewById(R.id.question_4);
if (textField.getText().toString().contentEquals(“life”))
score += 1;
//displayint toast message
CharSequence toastText = “You have scored ” + score + ” out of 4 questions”;
int duration = Toast.LENGTH_SHORT;
Toast toast = Toast.makeText(getApplicationContext(), toastText, duration);
toast.show();
}
}