Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package comq.example.android.squizer;
- import android.content.Intent;
- import android.net.Uri;
- import android.support.v7.app.AppCompatActivity;
- import android.os.Bundle;
- import android.view.View;
- import android.widget.CheckBox;
- import android.widget.EditText;
- import android.widget.RadioButton;
- import android.widget.Toast;
- public class MainActivity extends AppCompatActivity {
- int score = 0;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- }
- /**
- * This method is called when the SCOREME button is clicked.
- */
- public void scoreMe(View view) {
- /**
- * Takes the Name input from the user.
- */
- EditText nameTextInput = (EditText) findViewById(R.id.name_text_input);
- String nameInput = nameTextInput.getText().toString();
- /**
- * checking if the radio buttons are clicked.
- * @param Q1an1 indicate a representation of question 1 answer 1
- * and so on with the numbers.
- * @param Q1An1 indicate a boolean representation of question 1 answer 1
- * and so on with the numbers.
- */
- RadioButton Q1an1 = (RadioButton) findViewById(R.id.Q1an1);
- boolean Q1An1 = Q1an1.isChecked();
- RadioButton Q1an2 = (RadioButton) findViewById(R.id.Q1an2);
- boolean Q1An2 = Q1an2.isChecked();
- RadioButton Q2an1 = (RadioButton) findViewById(R.id.Q2an1);
- boolean Q2An1 = Q2an1.isChecked();
- RadioButton Q2an2 = (RadioButton) findViewById(R.id.Q2an2);
- boolean Q2An2 = Q2an2.isChecked();
- RadioButton Q2an3 = (RadioButton) findViewById(R.id.Q2an3);
- boolean Q2An3 = Q2an3.isChecked();
- RadioButton Q3an1 = (RadioButton) findViewById(R.id.Q3an1);
- boolean Q3An1 = Q3an1.isChecked();
- RadioButton Q3an2 = (RadioButton) findViewById(R.id.Q3an2);
- boolean Q3An2 = Q3an2.isChecked();
- RadioButton Q3an3 = (RadioButton) findViewById(R.id.Q3an3);
- boolean Q3An3 = Q3an3.isChecked();
- RadioButton Q4an1 = (RadioButton) findViewById(R.id.Q4an1);
- boolean Q4An1 = Q4an1.isChecked();
- RadioButton Q4an2 = (RadioButton) findViewById(R.id.Q4an2);
- boolean Q4An2 = Q4an2.isChecked();
- RadioButton Q4an3 = (RadioButton) findViewById(R.id.Q4an3);
- boolean Q4An3 = Q4an3.isChecked();
- /**
- * @param totalScore -the score after calculation.
- */
- int totalScore = calculateScore(Q1An1,Q1An2,Q2An1,Q2An2,Q2An3, Q3An1, Q3An2 ,Q3An3,
- Q4An1, Q4An2, Q4An3);
- /**
- * @param scoreMsg -the the msg the user gets.
- */
- String scoreMsg = "Yo " + nameInput + " you squeezed a " + totalScore +"out of 4 "
- +", "+ "Awesome job , Want some juice?";
- /**
- * Toasts the scoreMsg.
- */
- Toast.makeText(this, scoreMsg, Toast.LENGTH_LONG).show();
- }
- /**
- * Calculates the score of the the right answers.
- * @param Q1An1 indicate a boolean representation of question 1 answer 1
- * and so on with the numbers.
- * @return updated score
- */
- private int calculateScore( boolean Q1An1, boolean Q1An2, boolean Q2An1, boolean Q2An2,
- boolean Q2An3, boolean Q3An1 , boolean Q3An2,boolean Q3An3,
- boolean Q4An1, boolean Q4An2, boolean Q4An3) {
- int baseScore = 0;
- if(Q1An1) {
- baseScore = baseScore + 1;
- }
- if(Q1An2) {
- baseScore = baseScore + 0;
- }
- if(Q2An1) {
- baseScore = baseScore + 0;
- }
- if(Q2An2) {
- baseScore = baseScore + 1;
- }
- if(Q2An3) {
- baseScore = baseScore + 0;
- }
- if(Q3An1) {
- baseScore = baseScore + 0;
- }
- if(Q3An2) {
- baseScore = baseScore + 1;
- }
- if(Q3An3) {
- baseScore = baseScore + 0;
- }
- if(Q4An1) {
- baseScore = baseScore + 0;
- }
- if(Q4An2) {
- baseScore = baseScore + 0;
- }
- if(Q4An3) {
- baseScore = baseScore + 1;
- }
- return score + baseScore;
- }
- }
Add Comment
Please, Sign In to add comment