Guest User

Untitled

a guest
Jan 23rd, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.40 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 java.util.Random;
  9.  
  10. public class MainActivity extends AppCompatActivity {
  11. int scoreTeamA = 0;
  12. int scoreTeamB = 0;
  13. int random1 = 0;
  14.  
  15. @Override
  16. protected void onCreate(Bundle savedInstanceState) {
  17. super.onCreate(savedInstanceState);
  18. setContentView(R.layout.activity_main);
  19. displayForTeamA(0);
  20. displayForTeamB(0);
  21. }
  22.  
  23. /**
  24. * Displays the given score for Team A.
  25. */
  26. public void displayForTeamA(int score) {
  27. TextView scoreView = (TextView) findViewById(R.id.team_a_score);
  28. scoreView.setText(String.valueOf(score));
  29. }
  30.  
  31. /**
  32. * Displays the given score for Team B.
  33. */
  34. public void displayForTeamB(int score) {
  35. TextView scoreView = (TextView) findViewById(R.id.team_b_score);
  36. scoreView.setText(String.valueOf(score));
  37. }
  38.  
  39. /**
  40. * Displays the number for 3 points
  41. */
  42. public void addThreeForTeamA (View view){
  43. scoreTeamA = scoreTeamA + 3;
  44. displayForTeamA(scoreTeamA);
  45. }
  46. /**
  47. * Displays the number for 2 points
  48. */
  49. public void addTwoForTeamA (View view){
  50. scoreTeamA = scoreTeamA + 2;
  51. displayForTeamA(scoreTeamA);
  52. }
  53. /**
  54. * Displays the random number for team A
  55. */
  56. public void toRandomPositionA(View view) {
  57. Random random= new Random();
  58. scoreTeamA = scoreTeamA + random.nextInt(20) + 1;
  59. displayForTeamA(scoreTeamA);
  60. }
  61.  
  62. /**
  63. * Displays the number for 3 points for team B
  64. */
  65. public void addThreeForTeamB (View view){
  66. scoreTeamB = scoreTeamB + 3;
  67. displayForTeamB(scoreTeamB);
  68. }
  69. /**
  70. * Displays the number for 2 points for team B
  71. */
  72. public void addTwoForTeamB (View view){
  73. scoreTeamB = scoreTeamB + 2;
  74. displayForTeamB(scoreTeamB);
  75. }
  76. /**
  77. * Displays the random number for team B
  78. */
  79. public void toRandomPositionB(View view) {
  80. Random random= new Random();
  81. scoreTeamB = scoreTeamB + random.nextInt(20) + 1;
  82. displayForTeamB(scoreTeamB);
  83. }
  84.  
  85. //**Reset button for both teams
  86.  
  87. public void reset(View v) {
  88. scoreTeamA = 0;
  89. scoreTeamB = 0;
  90. displayForTeamA(scoreTeamA);
  91. displayForTeamB(scoreTeamB);
  92. }
  93.  
  94. }
Add Comment
Please, Sign In to add comment