Advertisement
Guest User

Untitled

a guest
Jan 11th, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.32 KB | None | 0 0
  1. package com.example.android.footballscoring;
  2.  
  3. import android.os.Bundle;
  4. import android.support.v7.app.AppCompatActivity;
  5. import android.view.View;
  6. import android.widget.TextView;
  7.  
  8. public class MainActivity extends AppCompatActivity {
  9.  
  10. // Tracks the game score for team A.
  11. int scoreTeamA = 0;
  12.  
  13. // Tracks the game score for team B.
  14. int scoreTeamB = 0;
  15.  
  16. // Tracks the number of yellow cards for team A.
  17. int yellowCardsTeamA = 0;
  18.  
  19. // Tracks the number of yellow cards for team B.
  20. int yellowCardsTeamB = 0;
  21.  
  22. // Tracks the number of red cards for team A.
  23. int redCardsTeamA = 0;
  24.  
  25. // Tracks the number of red cards for team B.
  26. int redCardsTeamB = 0;
  27.  
  28. @Override
  29. protected void onCreate(Bundle savedInstanceState) {
  30. super.onCreate(savedInstanceState);
  31. setContentView(R.layout.activity_main);
  32. displayForTeamA(0);
  33. }
  34.  
  35. /**
  36. * Displays the given score for Team A.
  37. */
  38. public void displayForTeamA(int score) {
  39. TextView scoreView = (TextView) findViewById(R.id.team_a_score);
  40. scoreView.setText(String.valueOf(score));
  41. }
  42.  
  43. /**
  44. * This method is called when the Goal button for team A is clicked.
  45. */
  46. public void addGoalTeamA(View view) {
  47. scoreTeamA = scoreTeamA + 1;
  48. displayForTeamA(scoreTeamA);
  49. }
  50.  
  51. /**
  52. * Displays the accumulated number of yellow cards for Team A.
  53. */
  54. public void displayYellowCardsForTeamA(int score) {
  55. TextView scoreView = (TextView) findViewById(R.id.team_a_yellow_cards);
  56. scoreView.setText(String.valueOf(score));
  57. }
  58.  
  59. /**
  60. * This method is called when the "Yellow card" button for team A is clicked.
  61. */
  62. public void addYellowCardTeamA(View view) {
  63. yellowCardsTeamA = yellowCardsTeamA + 1;
  64. displayYellowCardsForTeamA(yellowCardsTeamA);
  65. }
  66.  
  67. /**
  68. * Displays the accumulated number of red cards for Team A.
  69. */
  70. public void displayRedCardsForTeamA(int score) {
  71. TextView scoreView = (TextView) findViewById(R.id.team_a_red_cards);
  72. scoreView.setText(String.valueOf(score));
  73. }
  74.  
  75. /**
  76. * This method is called when the "Red card" button for team A is clicked.
  77. */
  78. public void addRedCardTeamA(View view) {
  79. redCardsTeamA = redCardsTeamA + 1;
  80. displayRedCardsForTeamA(redCardsTeamA);
  81. }
  82.  
  83. /**
  84. * Displays the given score for Team B.
  85. */
  86. public void displayForTeamB(int score) {
  87. TextView scoreView = (TextView) findViewById(R.id.team_b_score);
  88. scoreView.setText(String.valueOf(score));
  89. }
  90.  
  91. /**
  92. * This method is called when the Goal button for team B is clicked.
  93. */
  94. public void addGoalTeamB(View view) {
  95. scoreTeamB = scoreTeamB + 1;
  96. displayForTeamB(scoreTeamB);
  97. }
  98.  
  99. /**
  100. * Displays the accumulated number of yellow cards for Team B.
  101. */
  102. public void displayYellowCardsForTeamB(int score) {
  103. TextView scoreView = (TextView) findViewById(R.id.team_b_yellow_cards);
  104. scoreView.setText(String.valueOf(score));
  105. }
  106.  
  107. /**
  108. * This method is called when the "Yellow card" button for team B is clicked.
  109. */
  110. public void addYellowCardTeamB(View view) {
  111. yellowCardsTeamB = yellowCardsTeamB + 1;
  112. displayYellowCardsForTeamB(yellowCardsTeamB);
  113. }
  114.  
  115.  
  116. /**
  117. * Displays the accumulated number of red cards for Team B.
  118. */
  119. public void displayRedCardsForTeamB(int score) {
  120. TextView scoreView = (TextView) findViewById(R.id.team_b_red_cards);
  121. scoreView.setText(String.valueOf(score));
  122. }
  123.  
  124. /**
  125. * This method is called when the "Red card" button for team B is clicked.
  126. */
  127. public void addRedCardTeamB(View view) {
  128. redCardsTeamB = redCardsTeamB + 1;
  129. displayRedCardsForTeamB(redCardsTeamB);
  130. }
  131.  
  132.  
  133. /**
  134. * This method is called when the Reset button is clicked.
  135. */
  136. public void reset(View view) {
  137. scoreTeamA = 0;
  138. displayForTeamA(scoreTeamA);
  139. scoreTeamB = 0;
  140. displayForTeamB(scoreTeamB);
  141. yellowCardsTeamA = 0;
  142. displayYellowCardsForTeamA(yellowCardsTeamA);
  143. redCardsTeamA = 0;
  144. displayRedCardsForTeamA(redCardsTeamA);
  145. yellowCardsTeamB = 0;
  146. displayYellowCardsForTeamB(yellowCardsTeamB);
  147. redCardsTeamB = 0;
  148. displayRedCardsForTeamB(redCardsTeamB);
  149. }
  150. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement