Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.example.android.courtcounter;
- import android.content.res.ColorStateList;
- import android.graphics.Color;
- import android.support.v7.app.AppCompatActivity;
- import android.os.Bundle;
- import android.util.Log;
- import android.view.View;
- import android.widget.Button;
- import android.widget.TextView;
- import java.text.DecimalFormat;
- import java.util.Random;
- import static android.R.attr.id;
- import static android.R.attr.max;
- import static android.R.attr.min;
- public class MainActivity extends AppCompatActivity {
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- }
- int ScoreA, ScoreB, Throw;
- int RandomResult;
- String TeamID;
- int ThrowA, ThrowB;
- float accuracyTeamA, accuracyTeamB;
- int MissedThrowA, MissedThrowB;
- public void accuracy(int missedThrowA, int missedThrowB, int ThrowA, int ThrowB )
- {
- if(ThrowA > 0) {
- accuracyTeamA = ThrowA - missedThrowA;
- accuracyTeamA = accuracyTeamA /ThrowA * 100;
- }
- if(ThrowB >0) {
- accuracyTeamB = ThrowB - missedThrowB;
- accuracyTeamB = accuracyTeamB / ThrowB * 100;
- }
- TextView accuracyViewA = (TextView) findViewById(R.id.accuracyA);
- accuracyViewA.setText(String.valueOf(new DecimalFormat("##.#").format(accuracyTeamA)+" %"));
- TextView accuracyViewB = (TextView) findViewById(R.id.accuracyB);
- accuracyViewB.setText(String.valueOf(new DecimalFormat("##.#").format(accuracyTeamB)+" %"));
- // Log.d("AccuracyB:",Float.toString(accuracyTeamB));
- }
- public void displayScoreA(int ScoreA)
- {
- TextView scoreView = (TextView) findViewById(R.id.ScoreTextA);
- scoreView.setText(String.valueOf(ScoreA));
- }
- public void displayScoreB(int ScoreB)
- {
- TextView scoreView = (TextView) findViewById(R.id.ScoreTextB);
- scoreView.setText(String.valueOf(ScoreB));
- }
- public void Reset(View v)
- {
- TextView scoreViewA = (TextView) findViewById(R.id.ScoreTextA);
- scoreViewA.setText(String.valueOf(0));
- TextView scoreViewB = (TextView) findViewById(R.id.ScoreTextB);
- scoreViewB.setText(String.valueOf(0));
- TextView accuracyA = (TextView) findViewById(R.id.accuracyA);
- accuracyA.setText(String.valueOf(0));
- TextView accuracyB = (TextView) findViewById(R.id.accuracyB);
- accuracyB.setText(String.valueOf(0));
- }
- public void Notification(int Throw, String TeamID)
- {
- int greenColor = Color.parseColor("#1b5e20");
- int redColor = Color.parseColor("#d50000");
- TextView info = (TextView) findViewById(R.id.InfoTable);
- if (Throw <1)
- {
- info.setTextColor(redColor);
- info.setText((String.valueOf("YOU\nMISSED !!")));
- }
- else {
- info.setTextColor(greenColor);
- info.setText(String.valueOf("GREAT\nSHOT\n"+ TeamID+" !!"));
- }
- }
- public void add3ToA(View v){
- Throw=3;
- ThrowA = ThrowA +1;
- TeamID = "Team A";
- RandomizeThrow(Throw,TeamID);
- ScoreA = ScoreA +Throw;
- displayScoreA(ScoreA);
- Notification(Throw, TeamID);
- }
- public void add2ToA(View v){
- Throw=2;
- ThrowA = ThrowA +1;
- TeamID = "Team A";
- RandomizeThrow(Throw,TeamID);
- ScoreA = ScoreA +Throw;
- displayScoreA(ScoreA);
- Notification(Throw, TeamID);
- }
- public void add1ToA(View v){
- Throw=1;
- ThrowA = ThrowA +1;
- TeamID = "Team A";
- RandomizeThrow(Throw,TeamID);
- ScoreA = ScoreA +Throw;
- displayScoreA(ScoreA);
- Notification(Throw, TeamID);
- }
- public void add3ToB(View v){
- Throw=3;
- ThrowB = ThrowB +1;
- TeamID = "Team B";
- RandomizeThrow(Throw,TeamID);
- ScoreB = ScoreB +Throw;
- displayScoreB(ScoreB);
- Notification(Throw, TeamID);
- }
- public void add2ToB(View v){
- Throw = 2;
- ThrowB = ThrowB +1;
- TeamID = "Team B";
- RandomizeThrow(Throw,TeamID);
- ScoreB = ScoreB +Throw;
- displayScoreB(ScoreB);
- Notification(Throw, TeamID);
- }
- public void add1ToB(View v){
- Throw=1;
- ThrowB = ThrowB +1;
- TeamID = "Team B";
- RandomizeThrow(Throw,TeamID);
- ScoreB = ScoreB +Throw;
- displayScoreB(ScoreB);
- Notification(Throw, TeamID);
- }
- int RandomizeThrow(int RandomResult, String TeamID)
- {
- int min=0;
- int max=100;
- Random ran = new Random();
- if(ran != null) {
- if (Throw == 2) {
- int ran2 = (ran.nextInt(max - min + 1));
- if (ran2 < 50) {
- Throw = 2;
- } else {
- Throw = 0;
- if (TeamID == "Team B") {
- MissedThrowB = MissedThrowB + 1;
- }
- if (TeamID == "Team A"){
- MissedThrowA = MissedThrowA + 1;
- }
- }
- }
- if (Throw == 3) {
- int ran3 = (ran.nextInt(max - min+1));
- if (ran3 < 25) {
- Throw = 3;
- } else {
- Throw = 0;
- if(TeamID == "Team B"){
- MissedThrowB = MissedThrowB+1;
- }
- if (TeamID == "Team A"){
- MissedThrowA = MissedThrowA+1;
- }
- }
- }
- if (Throw == 1) {
- int ran1 = (ran.nextInt(max - min+1));
- if (ran1 < 75) {
- Throw = 1;
- }
- if (ran1 >= 75){
- Throw = 0;
- if(TeamID == "Team B"){
- MissedThrowB = MissedThrowB+1;
- }
- if (TeamID == "Team A"){
- MissedThrowA = MissedThrowA+1;
- }
- }
- }
- }
- accuracy(MissedThrowA,MissedThrowB,ThrowA,ThrowB);
- return RandomResult;
- }
- }
Add Comment
Please, Sign In to add comment