Guest User

Untitled

a guest
Feb 18th, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.28 KB | None | 0 0
  1. package comq.example.android.squizer;
  2.  
  3. import android.content.Intent;
  4. import android.net.Uri;
  5. import android.support.v7.app.AppCompatActivity;
  6. import android.os.Bundle;
  7. import android.view.View;
  8. import android.widget.CheckBox;
  9. import android.widget.EditText;
  10. import android.widget.RadioButton;
  11. import android.widget.Toast;
  12.  
  13. public class MainActivity extends AppCompatActivity {
  14. int score = 0;
  15. @Override
  16. protected void onCreate(Bundle savedInstanceState) {
  17. super.onCreate(savedInstanceState);
  18. setContentView(R.layout.activity_main);
  19. }
  20. /**
  21. * This method is called when the SCOREME button is clicked.
  22. */
  23. public void scoreMe(View view) {
  24. /**
  25. * Takes the Name input from the user.
  26. */
  27. EditText nameTextInput = (EditText) findViewById(R.id.name_text_input);
  28. String nameInput = nameTextInput.getText().toString();
  29. /**
  30. * checking if the radio buttons are clicked.
  31. * @param Q1an1 indicate a representation of question 1 answer 1
  32. * and so on with the numbers.
  33. * @param Q1An1 indicate a boolean representation of question 1 answer 1
  34. * and so on with the numbers.
  35. */
  36. RadioButton Q1an1 = (RadioButton) findViewById(R.id.Q1an1);
  37. boolean Q1An1 = Q1an1.isChecked();
  38. RadioButton Q1an2 = (RadioButton) findViewById(R.id.Q1an2);
  39. boolean Q1An2 = Q1an2.isChecked();
  40. RadioButton Q2an1 = (RadioButton) findViewById(R.id.Q2an1);
  41. boolean Q2An1 = Q2an1.isChecked();
  42. RadioButton Q2an2 = (RadioButton) findViewById(R.id.Q2an2);
  43. boolean Q2An2 = Q2an2.isChecked();
  44. RadioButton Q2an3 = (RadioButton) findViewById(R.id.Q2an3);
  45. boolean Q2An3 = Q2an3.isChecked();
  46. RadioButton Q3an1 = (RadioButton) findViewById(R.id.Q3an1);
  47. boolean Q3An1 = Q3an1.isChecked();
  48. RadioButton Q3an2 = (RadioButton) findViewById(R.id.Q3an2);
  49. boolean Q3An2 = Q3an2.isChecked();
  50. RadioButton Q3an3 = (RadioButton) findViewById(R.id.Q3an3);
  51. boolean Q3An3 = Q3an3.isChecked();
  52. RadioButton Q4an1 = (RadioButton) findViewById(R.id.Q4an1);
  53. boolean Q4An1 = Q4an1.isChecked();
  54. RadioButton Q4an2 = (RadioButton) findViewById(R.id.Q4an2);
  55. boolean Q4An2 = Q4an2.isChecked();
  56. RadioButton Q4an3 = (RadioButton) findViewById(R.id.Q4an3);
  57. boolean Q4An3 = Q4an3.isChecked();
  58. /**
  59. * @param totalScore -the score after calculation.
  60. */
  61. int totalScore = calculateScore(Q1An1,Q1An2,Q2An1,Q2An2,Q2An3, Q3An1, Q3An2 ,Q3An3,
  62. Q4An1, Q4An2, Q4An3);
  63. /**
  64. * @param scoreMsg -the the msg the user gets.
  65. */
  66. String scoreMsg = "Yo " + nameInput + " you squeezed a " + totalScore +"out of 4 "
  67. +", "+ "Awesome job , Want some juice?";
  68. /**
  69. * Toasts the scoreMsg.
  70. */
  71. Toast.makeText(this, scoreMsg, Toast.LENGTH_LONG).show();
  72. }
  73. /**
  74. * Calculates the score of the the right answers.
  75. * @param Q1An1 indicate a boolean representation of question 1 answer 1
  76. * and so on with the numbers.
  77. * @return updated score
  78. */
  79. private int calculateScore( boolean Q1An1, boolean Q1An2, boolean Q2An1, boolean Q2An2,
  80. boolean Q2An3, boolean Q3An1 , boolean Q3An2,boolean Q3An3,
  81. boolean Q4An1, boolean Q4An2, boolean Q4An3) {
  82. int baseScore = 0;
  83. if(Q1An1) {
  84. baseScore = baseScore + 1;
  85. }
  86. if(Q1An2) {
  87. baseScore = baseScore + 0;
  88. }
  89. if(Q2An1) {
  90. baseScore = baseScore + 0;
  91. }
  92. if(Q2An2) {
  93. baseScore = baseScore + 1;
  94. }
  95. if(Q2An3) {
  96. baseScore = baseScore + 0;
  97. }
  98. if(Q3An1) {
  99. baseScore = baseScore + 0;
  100. }
  101. if(Q3An2) {
  102. baseScore = baseScore + 1;
  103. }
  104. if(Q3An3) {
  105. baseScore = baseScore + 0;
  106. }
  107. if(Q4An1) {
  108. baseScore = baseScore + 0;
  109. }
  110. if(Q4An2) {
  111. baseScore = baseScore + 0;
  112. }
  113. if(Q4An3) {
  114. baseScore = baseScore + 1;
  115. }
  116. return score + baseScore;
  117. }
  118.  
  119. }
Add Comment
Please, Sign In to add comment