Guest User

Untitled

a guest
Feb 19th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.38 KB | None | 0 0
  1. package com.example.android.scorekeeper;
  2.  
  3. import android.support.v7.app.AppCompatActivity;
  4. import android.os.Bundle;
  5. import android.view.View;
  6. import android.widget.TextView;
  7.  
  8. import com.example.android.scorekeeper.R;
  9.  
  10. public class MainActivity extends AppCompatActivity {
  11.  
  12. int scoreTeamA = 0;
  13. int scoreTeamB = 0;
  14. int yellowCardTeamA = 0;
  15. int redCardTeamA = 0;
  16. int yellowCardTeamB = 0;
  17. int redCardTeamB = 0;
  18.  
  19. @Override
  20. protected void onCreate(Bundle savedInstanceState) {
  21. super.onCreate(savedInstanceState);
  22. setContentView(R.layout.activity_main);
  23. displayForTeamA(0);
  24. displayForTeamB(0);
  25. }
  26.  
  27. /**
  28. * Displays the given score, yellow and red cards for Team A.
  29. */
  30. public void displayForTeamA(int score) {
  31. TextView scoreView = (TextView) findViewById(R.id.team_a_score);
  32. scoreView.setText(String.valueOf(score));
  33.  
  34. }
  35.  
  36. public void displayYellowCardForTeamA(int foul) {
  37. TextView scoreView = (TextView) findViewById(R.id.yellowCardsTeamANumber);
  38. scoreView.setText(String.valueOf(foul));
  39.  
  40. }
  41.  
  42. public void displayRedCardForTeamA(int foul) {
  43. TextView scoreView = (TextView) findViewById(R.id.redCardsTeamANumber);
  44. scoreView.setText(String.valueOf(foul));
  45.  
  46. }
  47.  
  48. /**
  49. * Increments score, yellow and red card variables for team A
  50. */
  51.  
  52. public void scoreTeamA(View view) {
  53. scoreTeamA = scoreTeamA + 1;
  54. displayForTeamA(scoreTeamA);
  55. }
  56.  
  57. public void yellowCardForTeamA(View v) {
  58. yellowCardTeamA = yellowCardTeamA + 1;
  59. displayYellowCardForTeamA(yellowCardTeamA);
  60. }
  61.  
  62. public void redCardForTeamA(View v) {
  63. redCardTeamA = redCardTeamA + 1;
  64. displayRedCardForTeamA(redCardTeamA);
  65. }
  66.  
  67.  
  68. /**
  69. * Displays the given score, yellow and red cards for Team B.
  70. */
  71. public void displayForTeamB(int score) {
  72. TextView scoreView = (TextView) findViewById(R.id.team_b_score);
  73. scoreView.setText(String.valueOf(score));
  74.  
  75. }
  76.  
  77. public void displayYellowCardForTeamB(int foul) {
  78. TextView scoreView = (TextView) findViewById(R.id.yellowCardsTeamBNumber);
  79. scoreView.setText(String.valueOf(foul));
  80.  
  81. }
  82.  
  83. public void displayRedCardForTeamB(int foul) {
  84. TextView scoreView = (TextView) findViewById(R.id.redCardsTeamBNumber);
  85. scoreView.setText(String.valueOf(foul));
  86.  
  87. }
  88.  
  89. /**
  90. * Increments score, yellow and red card variables for team B.
  91. */
  92.  
  93. public void scoreTeamB(View view) {
  94. scoreTeamB = scoreTeamB + 1;
  95. displayForTeamB(scoreTeamB);
  96. }
  97.  
  98. public void yellowCardForTeamB(View v) {
  99. yellowCardTeamB = yellowCardTeamB + 1;
  100. displayYellowCardForTeamB(yellowCardTeamB);
  101. }
  102.  
  103. public void redCardForTeamB(View v) {
  104. redCardTeamB = redCardTeamB + 1;
  105. displayRedCardForTeamB(redCardTeamB);
  106. }
  107.  
  108.  
  109. /**
  110. * Resets score and cards for both teams.
  111. */
  112. public void resetScore(View v) {
  113. scoreTeamA = 0;
  114. scoreTeamB = 0;
  115. yellowCardTeamA = 0;
  116. redCardTeamA = 0;
  117. yellowCardTeamB = 0;
  118. redCardTeamB = 0;
  119. displayForTeamA(scoreTeamA);
  120. displayForTeamB(scoreTeamB);
  121. displayYellowCardForTeamA(yellowCardTeamA);
  122. displayRedCardForTeamA(redCardTeamA);
  123. displayYellowCardForTeamB(yellowCardTeamB);
  124. displayRedCardForTeamB(redCardTeamB);
  125. }
  126.  
  127.  
  128. }
Add Comment
Please, Sign In to add comment