Guest User

Untitled

a guest
Jan 18th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.64 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.  
  15. @Override
  16. protected void onCreate(Bundle savedInstanceState) {
  17. super.onCreate(savedInstanceState);
  18. setContentView(R.layout.activity_main);
  19. }
  20.  
  21. /**
  22. * Displays the given score for Team A.
  23. */
  24. public void displayForTeamA(int score) {
  25. TextView scoreView = (TextView) findViewById(R.id.team_a_score);
  26. scoreView.setText(String.valueOf(score));
  27. }
  28.  
  29. /**
  30. * Increase the score for Team A by 1 point.
  31. */
  32. public void addOneForTeamA(View v) {
  33. scoreTeamA = scoreTeamA + 1;
  34. displayForTeamA(scoreTeamA);
  35. }
  36.  
  37. /**
  38. * Increase the score for Team A by 2 points.
  39. */
  40. public void addTwoForTeamA(View v) {
  41. scoreTeamA = scoreTeamA + 2;
  42. displayForTeamA(scoreTeamA);
  43. }
  44.  
  45. /**
  46. * Increase the score for Team A by 3 points.
  47. */
  48. public void addThreeForTeamA(View v) {
  49. scoreTeamA = scoreTeamA + 3;
  50. displayForTeamA(scoreTeamA);
  51. }
  52.  
  53. /**
  54. * Increase the score for Team A by 6 points.
  55. */
  56. public void addSixForTeamA(View v) {
  57. scoreTeamA = scoreTeamA + 6;
  58. displayForTeamA(scoreTeamA);
  59. }
  60.  
  61. /**
  62. * Displays the given score for Team B.
  63. */
  64. public void displayForTeamB(int score) {
  65. TextView scoreView = (TextView) findViewById(R.id.team_b_score);
  66. scoreView.setText(String.valueOf(score));
  67. }
  68.  
  69. /**
  70. * Increase the score for Team B by 1 point.
  71. */
  72. public void addOneForTeamB(View v) {
  73. scoreTeamB = scoreTeamB + 1;
  74. displayForTeamB(scoreTeamB);
  75. }
  76.  
  77. /**
  78. * Increase the score for Team A by 2 points.
  79. */
  80. public void addTwoForTeamB(View v) {
  81. scoreTeamB = scoreTeamB + 2;
  82. displayForTeamB(scoreTeamB);
  83. }
  84.  
  85. /**
  86. * Increase the score for Team A by 3 points.
  87. */
  88. public void addThreeForTeamB(View v) {
  89. scoreTeamB = scoreTeamB + 3;
  90. displayForTeamB(scoreTeamB);
  91. }
  92.  
  93. /**
  94. * Increase the score for Team A by 3 points.
  95. */
  96. public void addSixForTeamB(View v) {
  97. scoreTeamB = scoreTeamB + 6;
  98. displayForTeamB(scoreTeamB);
  99. }
  100.  
  101. /**
  102. * Reset the score for Team A and Team B.
  103. */
  104. public void resetScore(View v) {
  105. scoreTeamB = 0;
  106. scoreTeamA = 0;
  107. displayForTeamA(scoreTeamA);
  108. displayForTeamB(scoreTeamB);
  109. }
  110.  
  111.  
  112.  
  113.  
  114. }
Add Comment
Please, Sign In to add comment