Created
April 19, 2016 15:59
-
-
Save Garretthh07/f941196c56ed373b5d6c1174a49b1605 to your computer and use it in GitHub Desktop.
CountScore
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.shunzhang.countscore; | |
import android.os.Bundle; | |
import android.support.v7.app.AppCompatActivity; | |
import android.view.View; | |
import android.widget.TextView; | |
public class MainActivity extends AppCompatActivity { | |
private int scoreTeamA = 0; | |
private int scoreTeamB = 0; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
} | |
/** | |
* Increase the score for Team A by 3 points. | |
* @param v | |
*/ | |
public void addThreeForTeamA(View v) { | |
scoreTeamA = scoreTeamA + 3; | |
displayForTeamA(scoreTeamA); | |
} | |
/** | |
* Increase the score for Team A by 2 points. | |
* @param v | |
*/ | |
public void addTwoForTeamA(View v) { | |
scoreTeamA = scoreTeamA + 2; | |
displayForTeamA(scoreTeamA); | |
} | |
/** | |
* Increase the score for Team A by 1 points. | |
* @param v | |
*/ | |
public void addOneForTeamA(View v) { | |
scoreTeamA = scoreTeamA + 1; | |
displayForTeamA(scoreTeamA); | |
} | |
/** | |
* Increase the score for Team A by 3 points. | |
* @param v | |
*/ | |
public void addThreeForTeamB(View v) { | |
scoreTeamB = scoreTeamB + 3; | |
displayForTeamB(scoreTeamB); | |
} | |
/** | |
* Increase the score for Team A by 2 points. | |
* @param v | |
*/ | |
public void addTwoForTeamB(View v) { | |
scoreTeamB = scoreTeamB + 2; | |
displayForTeamB(scoreTeamB); | |
} | |
/** | |
* Increase the score for Team A by 1 points. | |
* @param v | |
*/ | |
public void addOneForTeamB(View v) { | |
scoreTeamB = scoreTeamB + 1; | |
displayForTeamB(scoreTeamB); | |
} | |
public void resetScore(View v) { | |
scoreTeamA = 0; | |
scoreTeamB = 0; | |
displayForTeamA(scoreTeamA); | |
displayForTeamB(scoreTeamB); | |
} | |
/** | |
* Display the given score for Team A. | |
* @param score | |
*/ | |
public void displayForTeamA(int score) { | |
TextView scoreView = (TextView) findViewById(R.id.team_a_score); | |
scoreView.setText(String.valueOf(score)); | |
} | |
/** | |
* Display the given score for Team B. | |
* @param score | |
*/ | |
public void displayForTeamB(int score) { | |
TextView scoreView = (TextView) findViewById(R.id.team_b_score); | |
scoreView.setText(String.valueOf(score)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment