Advertisement
Guest User

Untitled

a guest
Feb 21st, 2017
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.73 KB | None | 0 0
  1. package com.example.android.scoregaa;
  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. int goalA = 0;
  11. int scoreTeamA = 0;
  12. int pointA = 0;
  13. int yellowCardTeamA = 0;
  14. int redCardTeamA = 0;
  15. int blackCardTeamA = 0;
  16. int goalB = 0;
  17. int scoreTeamB = 0;
  18. int pointB = 0;
  19. int yellowCardTeamB = 0;
  20. int redCardTeamB = 0;
  21. int blackCardTeamB = 0;
  22.  
  23. @Override
  24. protected void onCreate(Bundle savedInstanceState) {
  25. super.onCreate(savedInstanceState);
  26. setContentView(R.layout.activity_main);
  27. }
  28.  
  29. /**
  30. * This method adds one goal and increases the score by 3
  31. */
  32. public void addOneGoalTeamA(View view) {
  33. goalA = goalA + 1;
  34. scoreTeamA = scoreTeamA + 3;
  35. displayGoalTeamA(goalA);
  36. displayScoreTeamA(scoreTeamA);
  37. /**
  38. * This method add a "S" to the string Goal when the score is equal 2
  39. */
  40. if (goalA == 2) {
  41. String pluralGoalA = "Goals";
  42. addSToTeamA(pluralGoalA);
  43. }
  44. ;
  45. }
  46.  
  47. /**
  48. * This method displays the string Goals to the Team A
  49. */
  50. private void addSToTeamA(String message) {
  51. TextView priceTextView = (TextView) findViewById(R.id.pluralGoalTeamA);
  52. priceTextView.setText(message);
  53. }
  54.  
  55. /**
  56. * This display shows the goals made by the team A
  57. */
  58. public void displayGoalTeamA(int score) {
  59. TextView scoreView = (TextView) findViewById(R.id.goalTeamA);
  60. scoreView.setText(String.valueOf(score));
  61. }
  62.  
  63. /**
  64. * This method adds one Point and increases the score by 1
  65. */
  66. public void addOnePointForTeamA(View v) {
  67. pointA = pointA + 1;
  68. displayPointTeamA(pointA);
  69. scoreTeamA = scoreTeamA + 1;
  70. displayScoreTeamA(scoreTeamA);
  71. /**
  72. * This method add a "S" to the string Goal when the score is equal 2
  73. */
  74. if (pointA == 2) {
  75. String pluralPointA = "Points";
  76. pointsTeamA(pluralPointA);
  77. }
  78. }
  79.  
  80. /**
  81. * This method displays the string Points to the Team A
  82. */
  83. private void pointsTeamA(String message) {
  84. TextView priceTextView = (TextView) findViewById(R.id.pluralPointTeamA);
  85. priceTextView.setText(message);
  86. }
  87.  
  88.  
  89. /**
  90. * This display shows the points made by the team A
  91. */
  92. public void displayPointTeamA(int score) {
  93. TextView scoreView = (TextView) findViewById(R.id.pointTeamA);
  94. scoreView.setText(String.valueOf(score));
  95.  
  96. }
  97.  
  98. /**
  99. * This display shows the score made by the team A
  100. */
  101. public void displayScoreTeamA(int score) {
  102. TextView scoreView = (TextView) findViewById(R.id.scoreForTeamA);
  103. scoreView.setText(String.valueOf(score));
  104. }
  105.  
  106. /**
  107. * This method add one yellow card to the Team A
  108. */
  109. public void addYellowA(View view) {
  110. yellowCardTeamA = yellowCardTeamA + 1;
  111. displayYellowTeamA(yellowCardTeamA);
  112. }
  113.  
  114. /**
  115. * This display shows the yellow card given to the team A
  116. */
  117. public void displayYellowTeamA(int score) {
  118. TextView scoreView = (TextView) findViewById(R.id.yellowA);
  119. scoreView.setText(String.valueOf(score));
  120.  
  121. }
  122.  
  123. /**
  124. * This method add one red card to the Team A
  125. */
  126. public void addRedA(View view) {
  127. redCardTeamA = redCardTeamA + 1;
  128. displayRedTeamA(redCardTeamA);
  129. }
  130.  
  131. /**
  132. * This display shows the red card given to the team A
  133. */
  134. public void displayRedTeamA(int score) {
  135. TextView scoreView = (TextView) findViewById(R.id.redA);
  136. scoreView.setText(String.valueOf(score));
  137.  
  138. }
  139.  
  140. /**
  141. * This method add one black card to the Team A
  142. */
  143. public void addBlackA(View view) {
  144. blackCardTeamA = blackCardTeamA + 1;
  145. displayBlackTeamA(blackCardTeamA);
  146. }
  147.  
  148. /**
  149. * This display shows the black card given to the team A
  150. */
  151. public void displayBlackTeamA(int score) {
  152. TextView scoreView = (TextView) findViewById(R.id.blackA);
  153. scoreView.setText(String.valueOf(score));
  154.  
  155. }
  156.  
  157. /**
  158. * This method adds one goal and increases the score by 3 for team B
  159. */
  160. public void addOneGoalTeamB(View view) {
  161. goalB = goalB + 1;
  162. scoreTeamB = scoreTeamB + 3;
  163. displayGoalTeamB(goalB);
  164. displayScoreTeamB(scoreTeamB);
  165. /**
  166. * This method add a "S" to the string Goal when the score is equal 2
  167. */
  168. if (goalB == 2) {
  169. String pluralGoalB = "Goals";
  170. addSToTeamB(pluralGoalB);
  171. }
  172. }
  173.  
  174. /**
  175. * This method displays the string Goals to the Team B
  176. */
  177. private void addSToTeamB(String message) {
  178. TextView priceTextView = (TextView) findViewById(R.id.pluralGoalTeamB);
  179. priceTextView.setText(message);
  180. }
  181.  
  182. /**
  183. * This display shows the goals made by the team B
  184. */
  185. public void displayGoalTeamB(int score) {
  186. TextView scoreView = (TextView) findViewById(R.id.goalTeamB);
  187. scoreView.setText(String.valueOf(score));
  188. }
  189.  
  190. /**
  191. * This method adds one Point and increases the score by 1 for team B
  192. */
  193. public void addOnePointForTeamB(View v) {
  194. pointB = pointB + 1;
  195. displayPointTeamB(pointB);
  196. scoreTeamB = scoreTeamB + 1;
  197. displayScoreTeamB(scoreTeamB);
  198. /**
  199. * This method add a "S" to the string Goal when the score is equal 2
  200. */
  201. if (pointB == 2) {
  202. String pluralTeamB = "Points";
  203. pointsTeamB(pluralTeamB);
  204. }
  205. }
  206.  
  207. /**
  208. * This method displays the string Points to the Team B
  209. */
  210. private void pointsTeamB(String message) {
  211. TextView priceTextView = (TextView) findViewById(R.id.pluralPointTeamB);
  212. priceTextView.setText(message);
  213. }
  214.  
  215. /**
  216. * This display shows the points made by the team B
  217. */
  218. public void displayPointTeamB(int score) {
  219. TextView scoreView = (TextView) findViewById(R.id.pointTeamB);
  220. scoreView.setText(String.valueOf(score));
  221.  
  222. }
  223.  
  224. /**
  225. * This display shows the score made by the team B
  226. */
  227. public void displayScoreTeamB(int score) {
  228. TextView scoreView = (TextView) findViewById(R.id.scoreForTeamB);
  229. scoreView.setText(String.valueOf(score));
  230. }
  231.  
  232. /**
  233. * This method add one yellow card to the Team B
  234. */
  235. public void addYellowB(View view) {
  236. yellowCardTeamB = yellowCardTeamB + 1;
  237. displayYellowTeamB(yellowCardTeamB);
  238. }
  239.  
  240. /**
  241. * This display shows the yellow card given to the team A
  242. */
  243. public void displayYellowTeamB(int score) {
  244. TextView scoreView = (TextView) findViewById(R.id.yellowB);
  245. scoreView.setText(String.valueOf(score));
  246.  
  247. }
  248.  
  249. /**
  250. * This method add one red card to the Team B
  251. */
  252. public void addRedB(View view) {
  253. redCardTeamB = redCardTeamB + 1;
  254. displayRedTeamB(redCardTeamB);
  255. }
  256.  
  257. /**
  258. * This display shows the red card given to the team B
  259. */
  260. public void displayRedTeamB(int score) {
  261. TextView scoreView = (TextView) findViewById(R.id.redB);
  262. scoreView.setText(String.valueOf(score));
  263.  
  264. }
  265.  
  266. /**
  267. * This method add one black card to the Team B
  268. */
  269. public void addBlackB(View view) {
  270. blackCardTeamB = blackCardTeamB + 1;
  271. displayBlackTeamB(blackCardTeamB);
  272. }
  273.  
  274. /**
  275. * This display shows the black card given to the team A
  276. */
  277. public void displayBlackTeamB(int score) {
  278. TextView scoreView = (TextView) findViewById(R.id.blackB);
  279. scoreView.setText(String.valueOf(score));
  280.  
  281. }
  282.  
  283. public void reset(View view) {
  284. goalA = 0;
  285. scoreTeamA = 0;
  286. pointA = 0;
  287. yellowCardTeamA = 0;
  288. redCardTeamA = 0;
  289. blackCardTeamA = 0;
  290. goalB = 0;
  291. scoreTeamB = 0;
  292. pointB = 0;
  293. yellowCardTeamB = 0;
  294. redCardTeamB = 0;
  295. blackCardTeamB = 0;
  296. String pluralGoalA = "Goal";
  297. addSToTeamA(pluralGoalA);
  298. String pluralGoalB = "Goal";
  299. addSToTeamB(pluralGoalB);
  300. String pluralPointA = "Point";
  301. pointsTeamA(pluralPointA);
  302. String pluralPointB = "Point";
  303. pointsTeamB(pluralPointB);
  304. displayGoalTeamA(goalA);
  305. displayPointTeamA(pointA);
  306. displayScoreTeamA(scoreTeamA);
  307. displayYellowTeamA(yellowCardTeamA);
  308. displayRedTeamA(redCardTeamA);
  309. displayBlackTeamA(blackCardTeamA);
  310. displayGoalTeamB(goalB);
  311. displayPointTeamB(pointB);
  312. displayScoreTeamB(scoreTeamB);
  313. displayYellowTeamB(yellowCardTeamB);
  314. displayRedTeamB(redCardTeamB);
  315. displayBlackTeamB(blackCardTeamB);
  316.  
  317. }
  318. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement