Guest User

Untitled

a guest
Jan 16th, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.30 KB | None | 0 0
  1. package com.example.android.paokquizzapp;
  2.  
  3. import android.support.v7.app.AppCompatActivity;
  4. import android.os.Bundle;
  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. import android.widget.RadioGroup;
  11. import android.widget.Toast;
  12.  
  13. public class MainActivity extends AppCompatActivity {
  14.  
  15. private String fanName;
  16.  
  17. private boolean question1 = false;
  18. private boolean question2 = false;
  19. private boolean question3 = false;
  20. private boolean question4 = false;
  21. private boolean question5 = false;
  22. private boolean question6 = false;
  23. private boolean question7 = false;
  24.  
  25. private int score = 0;
  26.  
  27. private RadioButton radio_button1;
  28. private RadioButton radio_button2;
  29. private RadioButton radio_button3;
  30. private RadioButton radio_button4;
  31. private RadioButton radio_button7;
  32.  
  33.  
  34.  
  35. private CheckBox checkBox51;
  36. private CheckBox checkBox52;
  37. private CheckBox checkBox53;
  38. private CheckBox checkBox54;
  39.  
  40.  
  41. private CheckBox checkBox61;
  42. private CheckBox checkBox62;
  43. private CheckBox checkBox63;
  44. private CheckBox checkBox64;
  45.  
  46.  
  47.  
  48. @Override
  49. protected void onCreate(Bundle savedInstanceState) {
  50. super.onCreate(savedInstanceState);
  51. setContentView(R.layout.activity_main);
  52.  
  53. radio_button1 = (RadioButton)findViewById(R.id.radio_button13);
  54. radio_button2 = (RadioButton)findViewById(R.id.radio_button24);
  55. radio_button3 = (RadioButton)findViewById(R.id.radio_button33);
  56. radio_button4 = (RadioButton)findViewById(R.id.radio_button41);
  57. radio_button7 = (RadioButton)findViewById(R.id.radio_button71);
  58.  
  59.  
  60. checkBox51 = (CheckBox)findViewById(R.id.checkbox51);
  61. checkBox52 = (CheckBox)findViewById(R.id.checkbox52);
  62. checkBox53 = (CheckBox)findViewById(R.id.checkbox53);
  63. checkBox54 = (CheckBox)findViewById(R.id.checkbox54);
  64.  
  65.  
  66. checkBox61 = (CheckBox)findViewById(R.id.checkbox61);
  67. checkBox62 = (CheckBox)findViewById(R.id.checkbox62);
  68. checkBox63 = (CheckBox)findViewById(R.id.checkbox63);
  69. checkBox64 = (CheckBox)findViewById(R.id.checkbox64);
  70.  
  71. }
  72.  
  73. public void compute_result(View view){
  74.  
  75. //Gets the name of the fan
  76. EditText fanNameField = (EditText)findViewById(R.id.name_field);
  77. fanName = fanNameField.getText().toString();
  78.  
  79. //Calls a method which vomputes the score
  80. compute_score();
  81.  
  82. String toastMessage = createResultText();
  83.  
  84. //Toast message the result
  85. Toast toast = Toast.makeText(this, toastMessage, Toast.LENGTH_LONG);
  86. toast.show();
  87.  
  88. }
  89.  
  90. public void resetApp(View view){
  91. fanName = "";
  92.  
  93. question1 = false;
  94. radio_button1.setChecked(false);
  95.  
  96. question2 = false;
  97. radio_button2.setChecked(false);
  98.  
  99. question3 = false;
  100. radio_button3.setChecked(false);
  101.  
  102. question4 = false;
  103. radio_button4.setChecked(false);
  104.  
  105. question5 = false;
  106. checkBox51.setChecked(false);
  107. checkBox52.setChecked(false);
  108. checkBox53.setChecked(false);
  109. checkBox54.setChecked(false);
  110.  
  111. question6 = false;
  112. checkBox61.setChecked(false);
  113. checkBox62.setChecked(false);
  114. checkBox63.setChecked(false);
  115. checkBox64.setChecked(false);
  116.  
  117. question7 = false;
  118. radio_button7.setChecked(false);
  119.  
  120. score = 0;
  121.  
  122. //Toast message reset
  123. Toast toast = Toast.makeText(this, "The Score has been reset", Toast.LENGTH_SHORT);
  124. toast.show();
  125. }
  126.  
  127. public String createResultText(){
  128. String message;
  129.  
  130. message = "Hello "+fanName;
  131. if(score <2){
  132. message += "\n"+score+" of 7 - You are not a fan of PAOK!";
  133. } else if(score <4){
  134. message += "\n"+score+" of 7 - You have to try more";
  135. } else if(score<6){
  136. message += "\n"+score+" of 7 - Good, you are fan of PAOK";
  137. } else if(score == 6){
  138. message += "\n"+score+" of 7 - Almost perfect, you are a huge supporter of PAOK";
  139. } else if(score == 7){
  140. message += "\n"+score+" of 7 - WOW, you are a fanatic ultra of PAOK, my respects!";
  141. }
  142. return message;
  143. }
  144.  
  145. public void compute_score(){
  146. //Check question 1
  147. if (radio_button1.isChecked()) {
  148. question1 = true;
  149. score += 1;
  150. }
  151.  
  152. //Check question 2
  153. if (radio_button2.isChecked()) {
  154. question2 = true;
  155. score += 1;
  156. }
  157.  
  158. //Check question 3
  159. if (radio_button3.isChecked()) {
  160. question3 = true;
  161. score += 1;
  162. }
  163.  
  164. //Check question 4
  165. if (radio_button4.isChecked()) {
  166. question4 = true;
  167. score += 1;
  168. }
  169.  
  170. //Check question 5
  171. if(!checkBox51.isChecked() && checkBox52.isChecked() && !checkBox53.isChecked() && checkBox54.isChecked() ){
  172. question5 = true;
  173. score += 1;
  174. }
  175.  
  176. //Check question 6
  177. if(!checkBox61.isChecked() && !checkBox62.isChecked() && checkBox63.isChecked() && checkBox64.isChecked() ){
  178. question6 = true;
  179. score += 1;
  180. }
  181.  
  182. //Check question 7
  183. if (radio_button7.isChecked()) {
  184. question7 = true;
  185. score += 1;
  186. }
  187.  
  188. }
  189. }
Add Comment
Please, Sign In to add comment