Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.example.android.scorekeeper;
- import android.support.v7.app.AppCompatActivity;
- import android.os.Bundle;
- import android.view.View;
- import android.widget.TextView;
- import com.example.android.scorekeeper.R;
- public class MainActivity extends AppCompatActivity {
- int scoreTeamA = 0;
- int scoreTeamB = 0;
- int yellowCardTeamA = 0;
- int redCardTeamA = 0;
- int yellowCardTeamB = 0;
- int redCardTeamB = 0;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- displayForTeamA(0);
- displayForTeamB(0);
- }
- /**
- * Displays the given score, yellow and red cards for Team A.
- */
- public void displayForTeamA(int score) {
- TextView scoreView = (TextView) findViewById(R.id.team_a_score);
- scoreView.setText(String.valueOf(score));
- }
- public void displayYellowCardForTeamA(int foul) {
- TextView scoreView = (TextView) findViewById(R.id.yellowCardsTeamANumber);
- scoreView.setText(String.valueOf(foul));
- }
- public void displayRedCardForTeamA(int foul) {
- TextView scoreView = (TextView) findViewById(R.id.redCardsTeamANumber);
- scoreView.setText(String.valueOf(foul));
- }
- /**
- * Increments score, yellow and red card variables for team A
- */
- public void scoreTeamA(View view) {
- scoreTeamA = scoreTeamA + 1;
- displayForTeamA(scoreTeamA);
- }
- public void yellowCardForTeamA(View v) {
- yellowCardTeamA = yellowCardTeamA + 1;
- displayYellowCardForTeamA(yellowCardTeamA);
- }
- public void redCardForTeamA(View v) {
- redCardTeamA = redCardTeamA + 1;
- displayRedCardForTeamA(redCardTeamA);
- }
- /**
- * Displays the given score, yellow and red cards for Team B.
- */
- public void displayForTeamB(int score) {
- TextView scoreView = (TextView) findViewById(R.id.team_b_score);
- scoreView.setText(String.valueOf(score));
- }
- public void displayYellowCardForTeamB(int foul) {
- TextView scoreView = (TextView) findViewById(R.id.yellowCardsTeamBNumber);
- scoreView.setText(String.valueOf(foul));
- }
- public void displayRedCardForTeamB(int foul) {
- TextView scoreView = (TextView) findViewById(R.id.redCardsTeamBNumber);
- scoreView.setText(String.valueOf(foul));
- }
- /**
- * Increments score, yellow and red card variables for team B.
- */
- public void scoreTeamB(View view) {
- scoreTeamB = scoreTeamB + 1;
- displayForTeamB(scoreTeamB);
- }
- public void yellowCardForTeamB(View v) {
- yellowCardTeamB = yellowCardTeamB + 1;
- displayYellowCardForTeamB(yellowCardTeamB);
- }
- public void redCardForTeamB(View v) {
- redCardTeamB = redCardTeamB + 1;
- displayRedCardForTeamB(redCardTeamB);
- }
- /**
- * Resets score and cards for both teams.
- */
- public void resetScore(View v) {
- scoreTeamA = 0;
- scoreTeamB = 0;
- yellowCardTeamA = 0;
- redCardTeamA = 0;
- yellowCardTeamB = 0;
- redCardTeamB = 0;
- displayForTeamA(scoreTeamA);
- displayForTeamB(scoreTeamB);
- displayYellowCardForTeamA(yellowCardTeamA);
- displayRedCardForTeamA(redCardTeamA);
- displayYellowCardForTeamB(yellowCardTeamB);
- displayRedCardForTeamB(redCardTeamB);
- }
- }
Add Comment
Please, Sign In to add comment