Guest User

Untitled

a guest
Apr 19th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.85 KB | None | 0 0
  1. package com.example.android.wwiiquiz;
  2.  
  3. import android.content.Intent;
  4. import android.net.Uri;
  5. import android.os.Bundle;
  6. import android.support.v7.app.AppCompatActivity;
  7. import android.util.Log;
  8. import android.view.View;
  9. import android.widget.CheckBox;
  10. import android.widget.EditText;
  11. import android.widget.RadioButton;
  12. import android.widget.TextView;
  13. import android.widget.Toast;
  14.  
  15. import com.example.android.wwiiquiz.R;
  16.  
  17. import java.text.NumberFormat;
  18.  
  19. /**
  20. /**
  21. * This app displays an order form to order coffee.
  22. */
  23. public class MainActivity extends AppCompatActivity {
  24.  
  25. @Override
  26. protected void onCreate(Bundle savedInstanceState) {
  27. super.onCreate(savedInstanceState);
  28. setContentView(R.layout.activity_main);
  29. }
  30.  
  31.  
  32.  
  33. /**
  34. * This method is called when the RESULTS button is clicked.
  35. */
  36. public void submitAnswers(View view) {
  37.  
  38. int correctAnswers = 0;
  39.  
  40. //Question 1 conditions
  41. RadioButton question1answer = (RadioButton) findViewById(R.id.question1_answer);
  42. boolean question1correct = question1answer.isChecked();
  43. Log.v("MainActivity", "Answer :" + question1answer);
  44.  
  45. if (question1correct) {
  46. correctAnswers = correctAnswers + 1;
  47. }
  48. //Question 2 conditions
  49. CheckBox question2germany = (CheckBox) findViewById(R.id.question2_germany);
  50. boolean question2germanychecked = question2germany.isChecked();
  51. Log.v("MainActivity", "Answer: " + question2germany);
  52.  
  53. CheckBox question2japan = (CheckBox) findViewById(R.id.question2_japan);
  54. boolean question2japanchecked = question2japan.isChecked();
  55. Log.v("MainActivity", "Answer: " + question2japan);
  56.  
  57. CheckBox question2italy = (CheckBox) findViewById(R.id.question2_italy);
  58. boolean question2italychecked = question2italy.isChecked();
  59. Log.v("MainActivity", "Answer: " + question2italy);
  60.  
  61. if(question2germanychecked && question2japanchecked && question2italychecked) {
  62. correctAnswers = correctAnswers + 1;
  63. }
  64. //Question 3 conditions
  65. RadioButton question3answer = (RadioButton) findViewById(R.id.question3_answer);
  66. boolean question3correct = question3answer.isChecked();
  67. Log.v("MainActivity", "Answer :" + question3answer);
  68.  
  69. if(question3correct) {
  70. correctAnswers = correctAnswers +1;
  71. }
  72. //Question 4 conditions
  73. CheckBox question4britain = (CheckBox) findViewById(R.id.question4_britain);
  74. boolean question4britainchecked = question4britain.isChecked();
  75. Log.v("MainActivity", "Answer: " + question4britain);
  76.  
  77. CheckBox question4france = (CheckBox) findViewById(R.id.question4_france);
  78. boolean question4francechecked = question4france.isChecked();
  79. Log.v("MainActivity", "Answer: " + question4france);
  80.  
  81. if(question4britainchecked && question4francechecked) {
  82. correctAnswers = correctAnswers + 1;
  83. }
  84.  
  85. //Bonus question condition
  86. EditText answerfield = (EditText) findViewById(R.id.bonus_answer);
  87. String answer5 = answerfield.getText().toString();
  88. Log.v("MainActivity", "Answer: " + answerfield);
  89.  
  90. if (answer5.equals("Enigma")) {
  91. correctAnswers = correctAnswers + 1;
  92.  
  93. if (correctAnswers ==5) {
  94. CharSequence allcorrect = "Congrats! You got all the questions AND the Bonus!";
  95. int duration = Toast.LENGTH_SHORT;
  96. Toast goodjob = Toast.makeText(getApplicationContext(), allcorrect, duration);
  97. goodjob.show();
  98. } else if (correctAnswers <5) {
  99. CharSequence other = "You got " + correctAnswers + " answers correct";
  100. int duration = Toast.LENGTH_SHORT;
  101. Toast results = Toast.makeText(getApplicationContext(), other, duration);
  102. results.show();
  103. }
  104.  
  105.  
  106.  
  107. }
  108.  
  109.  
  110. }}
Add Comment
Please, Sign In to add comment