Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.example.android.earthquake;
- import android.content.Context;
- import android.content.Intent;
- import android.net.Uri;
- import android.os.Bundle;
- import android.support.v7.app.AppCompatActivity;
- import android.text.Editable;
- import android.util.Log;
- import android.view.Gravity;
- import android.view.View;
- import android.view.WindowManager;
- import android.widget.CheckBox;
- import android.widget.EditText;
- import android.widget.RadioButton;
- import android.widget.TextView;
- import android.widget.Toast;
- import java.text.NumberFormat;
- public class MainActivity extends AppCompatActivity {
- private static final String LOG_TAG = MainActivity.class.getSimpleName();
- // Question 1
- RadioButton question1_choice4;
- // Question 2
- RadioButton question2_choice1;
- // Question 3
- CheckBox question3_choice1;
- CheckBox question3_choice2;
- CheckBox question3_choice3;
- CheckBox question3_choice4;
- // Question 4
- RadioButton question4_choice1;
- // Question 5
- EditText question5_answer;
- // Question 6
- RadioButton question6_choice2;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- // Hide the keyboard
- this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
- setContentView(R.layout.activity_main);
- }
- public void submitAnswers(View view) {
- CharSequence resultsDisplay;
- Log.e(LOG_TAG, " " + this.findViewById(R.id.question1_choice4));
- int answer1_score;
- int answer2_score;
- int answer3_score;
- int answer4_score;
- int answer5_score;
- int answer6_score;
- int answer7_score;
- int answer8_score;
- int answer9_score;
- int answer10_score;
- int final_score;
- //------------------------------------------------------------------------------------------
- // Question 1 - Correct Answer is #4 (reverse)
- //------------------------------------------------------------------------------------------
- Boolean answer1;
- question1_choice4 = (RadioButton) this.findViewById(R.id.question1_choice4);
- answer1 = question1_choice4.isChecked();
- if (answer1) {
- answer1_score = 1;
- } else {
- answer1_score = 0;
- }
- //------------------------------------------------------------------------------------------
- // Question 2 - Correct Answer is #1 (Strike-slip)
- //------------------------------------------------------------------------------------------
- Boolean answer2;
- question2_choice1 = (RadioButton) this.findViewById(R.id.question2_choice1);
- answer2 = question2_choice1.isChecked();
- if (answer2) {
- answer2_score = 1;
- } else {
- answer2_score = 0;
- }
- //------------------------------------------------------------------------------------------
- // Question 3 - Correct Answers are #3 (Strike-slip) and #4 (Left-lateral strike-slip)
- //------------------------------------------------------------------------------------------
- Boolean answer3_choice1;
- Boolean answer3_choice2;
- Boolean answer3_choice3;
- Boolean answer3_choice4;
- question3_choice1 = (CheckBox) this.findViewById(R.id.question3_choice1);
- question3_choice2 = (CheckBox) this.findViewById(R.id.question3_choice2);
- question3_choice3 = (CheckBox) this.findViewById(R.id.question3_choice3);
- question3_choice4 = (CheckBox) this.findViewById(R.id.question3_choice4);
- answer3_choice1 = question3_choice1.isChecked();
- answer3_choice2 = question3_choice2.isChecked();
- answer3_choice3 = question3_choice3.isChecked();
- answer3_choice4 = question3_choice4.isChecked();
- if (!answer3_choice1 && !answer3_choice2 && answer3_choice3 && answer3_choice4) {
- answer3_score = 1;
- } else {
- answer3_score = 0;
- }
- //------------------------------------------------------------------------------------------
- // Question 4 - Correct Answer is #1 (Normal)
- //------------------------------------------------------------------------------------------
- Boolean answer4;
- question4_choice1 = (RadioButton) this.findViewById(R.id.question4_choice1);
- answer4 = question4_choice1.isChecked();
- if (answer4) {
- answer4_score = 1;
- } else {
- answer4_score = 0;
- }
- //------------------------------------------------------------------------------------------
- // Question 5 - Correct Answer is "Seismograph"
- //------------------------------------------------------------------------------------------
- String answer5;
- question5_answer = (EditText) this.findViewById(R.id.question5_answer);
- answer5 = question5_answer.getText().toString().toLowerCase();
- if (answer5.equals("seismograph")) {
- answer5_score = 1;
- } else {
- answer5_score = 0;
- }
- //------------------------------------------------------------------------------------------
- // Question 6 - Correct Answer is #2 (No)
- //------------------------------------------------------------------------------------------
- Boolean answer6;
- question6_choice2 = (RadioButton) this.findViewById(R.id.question6_choice2);
- answer6 = question6_choice2.isChecked();
- if (answer6) {
- answer6_score = 1;
- } else {
- answer6_score = 0;
- }
- //------------------------------------------------------------------------------------------
- // Final Score
- //------------------------------------------------------------------------------------------
- final_score = answer1_score + answer2_score + answer3_score + answer4_score + answer5_score +
- answer6_score;
- if (final_score == 6) {
- resultsDisplay = "Great Job! You scored 6 out of 6";
- } else {
- resultsDisplay = "You need to study more. You scored " + final_score + " out of 6";
- }
- Context context = getApplicationContext();
- int duration = Toast.LENGTH_LONG;
- Toast toast = Toast.makeText(context, resultsDisplay, duration);
- toast.setGravity(Gravity.CENTER, 0, 0);
- toast.show();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement