Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save napiorka-design/765def51fc27c618cc6b26b3c1cb83d6 to your computer and use it in GitHub Desktop.
Save napiorka-design/765def51fc27c618cc6b26b3c1cb83d6 to your computer and use it in GitHub Desktop.
Basketball counter app
package com.example.android.courtcounter;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
int scoreTeamA = 0;
int scoreTeamB = 8;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void addFreeThrowForTeamA(View v){
scoreTeamA = scoreTeamA + 1;
displayForTeamA(scoreTeamA);
}
public void addTwoForTeamA(View v){
scoreTeamA = scoreTeamA + 2;
displayForTeamA(scoreTeamA);
}
public void addThreeForTeamA(View v){
scoreTeamA = scoreTeamA + 3;
displayForTeamA(scoreTeamA);
}
/**
* 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));
}
public void addFreeThrowForTeamB(View v){
scoreTeamB = scoreTeamB + 1;
displayForTeamB(scoreTeamB);
}
public void addTwoForTeamB(View v){
scoreTeamB = scoreTeamB + 2;
displayForTeamB(scoreTeamB);
}
public void addThreeForTeamB(View v){
scoreTeamB = scoreTeamB + 3;
displayForTeamB(scoreTeamB);
}
/**
* 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));
}
public void resetButton(View v){
scoreTeamA = 0;
scoreTeamB = 0;
displayForTeamA(0);
displayForTeamB(0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment