daily pastebin goal
76%
SHARE
TWEET

Untitled

a guest Mar 26th, 2019 52 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package android.example.sharkquiz;
  2.  
  3. import android.support.v7.app.AppCompatActivity;
  4. import android.os.Bundle;
  5. import android.view.View;
  6. import android.widget.CheckBox;
  7. import android.widget.CompoundButton;
  8. import android.widget.EditText;
  9. import android.widget.RadioButton;
  10. import android.widget.RadioGroup;
  11. import android.widget.TextView;
  12. import android.widget.Toast;
  13.  
  14. public class MainActivity extends AppCompatActivity {
  15.  
  16.     private int score = 0;
  17.     private RadioGroup questionOneTf;
  18.     private CheckBox checkBox1;
  19.     private CheckBox checkBox2;
  20.     private CheckBox checkBox3;
  21.     private RadioGroup questionThreeTf;
  22.     private EditText sharkAnswer;
  23.  
  24.     @Override
  25.     protected void onCreate(Bundle savedInstanceState) {
  26.         super.onCreate(savedInstanceState);
  27.         setContentView(R.layout.activity_main);
  28.  
  29.  
  30.         //When True or False is Selected for question 1
  31.         questionOneTf = (RadioGroup) findViewById(R.id.question_one_true_false_radio_group);
  32.         questionOneTf.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
  33.             @Override
  34.             public void onCheckedChanged(RadioGroup group, int checkedId) {
  35.                 if(checkedId== R.id.question_one_true)
  36.                     score++;
  37.                 else
  38.                     score--;
  39.             }
  40.         });
  41.           boolean questionOneTrue = ((RadioButton) findViewById(R.id.question_one_true)).isChecked();
  42.  
  43.  
  44.         //When Answers are checked for question 2
  45.         checkBox1 = (CheckBox) findViewById(R.id.question_two_box_1);
  46.         checkBox1.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
  47.             @Override
  48.             public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
  49.                 if(isChecked)
  50.                     score++;
  51.                 else
  52.                     score--;
  53.             }
  54.         });
  55.          // boolean sharksHearing = checkBox1.isChecked();
  56.  
  57.         checkBox2 = (CheckBox) findViewById(R.id.question_two_box_2);
  58.         checkBox2.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
  59.             @Override
  60.             public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
  61.                 if(isChecked)
  62.                     score++;
  63.                 else
  64.                     score--;
  65.             }
  66.         });
  67.  
  68.         checkBox3 = (CheckBox) findViewById(R.id.question_two_box_3);
  69.         checkBox3.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
  70.             @Override
  71.             public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
  72.                 if(isChecked)
  73.                     score++;
  74.                 else
  75.                     score--;
  76.             }
  77.         });
  78.  
  79.         //When true or false is selected for Question 3
  80.         questionThreeTf = (RadioGroup) findViewById(R.id.question_three_true_false_radio_group);
  81.         questionThreeTf.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
  82.             @Override
  83.             public void onCheckedChanged(RadioGroup group, int checkedId) {
  84.                 if(checkedId== R.id.question_three_true)
  85.                     score++;
  86.                 else
  87.                     score--;
  88.             }
  89.         });
  90.  
  91.         sharkAnswer = (EditText) findViewById(R.id.largest_shark);
  92.     }
  93.  
  94.     //This method is called when the Submit Quiz button is selected
  95.  
  96.     public void submitQuiz(View view) {
  97.         if(sharkAnswer.getText().toString().equals("Whale Shark"))
  98.             score++;
  99.  
  100.         Toast.makeText(this, "SCORE "+score, Toast.LENGTH_LONG).show();
  101.  
  102.         clear();
  103.  
  104.     }
  105.  
  106.     private void clear(){
  107.         checkBox1.setChecked(false);
  108.         checkBox2.setChecked(false);
  109.         checkBox3.setChecked(false);
  110.         questionOneTf.clearCheck();
  111.         questionThreeTf.clearCheck();
  112.         sharkAnswer.setText(null);
  113.         score=0;
  114.     }
  115.  
  116. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top