Advertisement
Guest User

Untitled

a guest
Mar 30th, 2017
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.88 KB | None | 0 0
  1. package com.example.android.quizapp;
  2.  
  3. import android.os.Bundle;
  4. import android.support.v7.app.AppCompatActivity;
  5. import android.util.Log;
  6. import android.view.View;
  7. import android.widget.CheckBox;
  8. import android.widget.EditText;
  9. import android.widget.RadioButton;
  10.  
  11. public class MainActivity extends AppCompatActivity {
  12.  
  13. @Override
  14. protected void onCreate(Bundle savedInstanceState) {
  15. super.onCreate(savedInstanceState);
  16. setContentView(R.layout.activity_main);
  17. }
  18.  
  19. public void submitAnswers(View view) {
  20. // Process student name field
  21. EditText studentName = (EditText) findViewById(R.id.full_name_field);
  22. String studentNameString = studentName.getText().toString();
  23. if (studentNameString.isEmpty() || studentNameString.length() == 0 || studentNameString.equals("")) {
  24. Log.i("MainActivity", "You didn't provide your full name");
  25. } else {
  26. Log.i("MainActivity", studentNameString);
  27. }
  28.  
  29. // Processing Question 1:
  30. CheckBox q1Answer1 = (CheckBox) findViewById(R.id.question_1_checkbox_1);
  31. CheckBox q1Answer2 = (CheckBox) findViewById(R.id.question_1_checkbox_2);
  32. CheckBox q1Answer3 = (CheckBox) findViewById(R.id.question_1_checkbox_3);
  33. CheckBox q1Answer4 = (CheckBox) findViewById(R.id.question_1_checkbox_4);
  34. CheckBox q1Answer5 = (CheckBox) findViewById(R.id.question_1_checkbox_5);
  35. // Determining the correct answer for Question 1:
  36. if (q1Answer1.isChecked() || q1Answer4.isChecked() || q1Answer5.isChecked() && (q1Answer2.isChecked() || q1Answer3.isChecked())) {
  37. Log.i("MainActivity", "Q1: wrong answer");
  38. } else if (q1Answer2.isChecked() && q1Answer3.isChecked()) {
  39. Log.i("MainActivity", "Q1: Correct Answer");
  40. } else if (q1Answer2.isChecked() || q1Answer3.isChecked()) {
  41. Log.i("MainActivity", "Q1: Wrong Answer");
  42. } else {
  43. Log.i("MainActivity", "Q1: No Answer provided");
  44. }
  45.  
  46. // Processing Question 2:
  47. RadioButton q2Answer1 = (RadioButton) findViewById(R.id.question_2_radio_1);
  48. RadioButton q2Answer2 = (RadioButton) findViewById(R.id.question_2_radio_2);
  49. RadioButton q2Answer3 = (RadioButton) findViewById(R.id.question_2_radio_3);
  50. // Determining the correct answer for Question 2:
  51. if (q2Answer1.isChecked()) {
  52. Log.i("MainActivity", "Q2: Correct Answer");
  53. } else if (q2Answer2.isChecked() || q2Answer3.isChecked()) {
  54. Log.i("MainActivity", "Q2: Wrong Answer");
  55. } else {
  56. Log.i("MainActivity", "Q2: No Answer provided!");
  57. }
  58.  
  59. // Processing Question 3:
  60. RadioButton q3Answer1 = (RadioButton) findViewById(R.id.question_3_radio_1);
  61. RadioButton q3Answer2 = (RadioButton) findViewById(R.id.question_3_radio_2);
  62. RadioButton q3Answer3 = (RadioButton) findViewById(R.id.question_3_radio_3);
  63. // Determining the correct answer for Question 3:
  64. if (q3Answer2.isChecked()) {
  65. Log.i("MainActivity", "Q2: Correct Answer");
  66. } else if (q3Answer1.isChecked() || q3Answer3.isChecked()) {
  67. Log.i("MainActivity", "Q2: Wrong Answer");
  68. } else {
  69. Log.i("MainActivity", "Q3: No Answer provided!");
  70. }
  71.  
  72. // Processing Question 4:
  73. CheckBox q4Answer1 = (CheckBox) findViewById(R.id.question_4_checkbox_1);
  74. CheckBox q4Answer2 = (CheckBox) findViewById(R.id.question_4_checkbox_2);
  75. CheckBox q4Answer3 = (CheckBox) findViewById(R.id.question_4_checkbox_3);
  76. // Determining the correct answer for Question 1:
  77. if (q4Answer1.isChecked() || q4Answer2.isChecked()) {
  78. Log.i("MainActivity", "Q4: wrong answer");
  79. } else if (q4Answer3.isChecked()) {
  80. Log.i("MainActivity", "Q4: Correct Answer");
  81. } else {
  82. Log.i("MainActivity", "Q4: No Answer provided!");
  83. }
  84. }
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement