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;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- }
- /**
- * Displays the given score for Team A.
- */
- public void displayForTeamA(int score) {
- TextView scoreView = (TextView) findViewById(R.id.team_a_score);
- scoreView.setText(String.valueOf(score));
- }
- /**
- * Increase the score for Team A by 1 point.
- */
- public void addOneForTeamA(View v) {
- scoreTeamA = scoreTeamA + 1;
- displayForTeamA(scoreTeamA);
- }
- /**
- * Increase the score for Team A by 2 points.
- */
- public void addTwoForTeamA(View v) {
- scoreTeamA = scoreTeamA + 2;
- displayForTeamA(scoreTeamA);
- }
- /**
- * Increase the score for Team A by 3 points.
- */
- public void addThreeForTeamA(View v) {
- scoreTeamA = scoreTeamA + 3;
- displayForTeamA(scoreTeamA);
- }
- /**
- * Increase the score for Team A by 6 points.
- */
- public void addSixForTeamA(View v) {
- scoreTeamA = scoreTeamA + 6;
- displayForTeamA(scoreTeamA);
- }
- /**
- * Displays the given score for Team B.
- */
- public void displayForTeamB(int score) {
- TextView scoreView = (TextView) findViewById(R.id.team_b_score);
- scoreView.setText(String.valueOf(score));
- }
- /**
- * Increase the score for Team B by 1 point.
- */
- public void addOneForTeamB(View v) {
- scoreTeamB = scoreTeamB + 1;
- displayForTeamB(scoreTeamB);
- }
- /**
- * Increase the score for Team A by 2 points.
- */
- public void addTwoForTeamB(View v) {
- scoreTeamB = scoreTeamB + 2;
- displayForTeamB(scoreTeamB);
- }
- /**
- * Increase the score for Team A by 3 points.
- */
- public void addThreeForTeamB(View v) {
- scoreTeamB = scoreTeamB + 3;
- displayForTeamB(scoreTeamB);
- }
- /**
- * Increase the score for Team A by 3 points.
- */
- public void addSixForTeamB(View v) {
- scoreTeamB = scoreTeamB + 6;
- displayForTeamB(scoreTeamB);
- }
- /**
- * Reset the score for Team A and Team B.
- */
- public void resetScore(View v) {
- scoreTeamB = 0;
- scoreTeamA = 0;
- displayForTeamA(scoreTeamA);
- displayForTeamB(scoreTeamB);
- }
- }
Add Comment
Please, Sign In to add comment