Guest User

Untitled

a guest
Jan 22nd, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.17 KB | None | 0 0
  1. package com.example.android.courtcounter;
  2.  
  3. import android.content.res.ColorStateList;
  4. import android.graphics.Color;
  5. import android.support.v7.app.AppCompatActivity;
  6. import android.os.Bundle;
  7. import android.util.Log;
  8. import android.view.View;
  9. import android.widget.Button;
  10. import android.widget.TextView;
  11.  
  12. import java.text.DecimalFormat;
  13. import java.util.Random;
  14.  
  15. import static android.R.attr.id;
  16. import static android.R.attr.max;
  17. import static android.R.attr.min;
  18.  
  19. public class MainActivity extends AppCompatActivity {
  20.  
  21. @Override
  22. protected void onCreate(Bundle savedInstanceState) {
  23. super.onCreate(savedInstanceState);
  24. setContentView(R.layout.activity_main);
  25. }
  26.  
  27. int ScoreA, ScoreB, Throw;
  28. int RandomResult;
  29. String TeamID;
  30. int ThrowA, ThrowB;
  31. float accuracyTeamA, accuracyTeamB;
  32. int MissedThrowA, MissedThrowB;
  33.  
  34.  
  35.  
  36. public void accuracy(int missedThrowA, int missedThrowB, int ThrowA, int ThrowB )
  37. {
  38.  
  39. if(ThrowA > 0) {
  40. accuracyTeamA = ThrowA - missedThrowA;
  41. accuracyTeamA = accuracyTeamA /ThrowA * 100;
  42. }
  43.  
  44. if(ThrowB >0) {
  45. accuracyTeamB = ThrowB - missedThrowB;
  46. accuracyTeamB = accuracyTeamB / ThrowB * 100;
  47. }
  48.  
  49. TextView accuracyViewA = (TextView) findViewById(R.id.accuracyA);
  50. accuracyViewA.setText(String.valueOf(new DecimalFormat("##.#").format(accuracyTeamA)+" %"));
  51.  
  52. TextView accuracyViewB = (TextView) findViewById(R.id.accuracyB);
  53. accuracyViewB.setText(String.valueOf(new DecimalFormat("##.#").format(accuracyTeamB)+" %"));
  54.  
  55. // Log.d("AccuracyB:",Float.toString(accuracyTeamB));
  56. }
  57.  
  58. public void displayScoreA(int ScoreA)
  59. {
  60. TextView scoreView = (TextView) findViewById(R.id.ScoreTextA);
  61. scoreView.setText(String.valueOf(ScoreA));
  62. }
  63.  
  64. public void displayScoreB(int ScoreB)
  65. {
  66. TextView scoreView = (TextView) findViewById(R.id.ScoreTextB);
  67. scoreView.setText(String.valueOf(ScoreB));
  68. }
  69.  
  70. public void Reset(View v)
  71. {
  72. TextView scoreViewA = (TextView) findViewById(R.id.ScoreTextA);
  73. scoreViewA.setText(String.valueOf(0));
  74.  
  75. TextView scoreViewB = (TextView) findViewById(R.id.ScoreTextB);
  76. scoreViewB.setText(String.valueOf(0));
  77.  
  78. TextView accuracyA = (TextView) findViewById(R.id.accuracyA);
  79. accuracyA.setText(String.valueOf(0));
  80.  
  81. TextView accuracyB = (TextView) findViewById(R.id.accuracyB);
  82. accuracyB.setText(String.valueOf(0));
  83. }
  84.  
  85. public void Notification(int Throw, String TeamID)
  86. {
  87. int greenColor = Color.parseColor("#1b5e20");
  88. int redColor = Color.parseColor("#d50000");
  89.  
  90. TextView info = (TextView) findViewById(R.id.InfoTable);
  91. if (Throw <1)
  92. {
  93. info.setTextColor(redColor);
  94. info.setText((String.valueOf("YOU\nMISSED !!")));
  95.  
  96. }
  97. else {
  98. info.setTextColor(greenColor);
  99. info.setText(String.valueOf("GREAT\nSHOT\n"+ TeamID+" !!"));
  100. }
  101.  
  102. }
  103.  
  104.  
  105. public void add3ToA(View v){
  106. Throw=3;
  107. ThrowA = ThrowA +1;
  108. TeamID = "Team A";
  109. RandomizeThrow(Throw,TeamID);
  110. ScoreA = ScoreA +Throw;
  111. displayScoreA(ScoreA);
  112. Notification(Throw, TeamID);
  113.  
  114.  
  115. }
  116.  
  117. public void add2ToA(View v){
  118. Throw=2;
  119. ThrowA = ThrowA +1;
  120. TeamID = "Team A";
  121. RandomizeThrow(Throw,TeamID);
  122. ScoreA = ScoreA +Throw;
  123. displayScoreA(ScoreA);
  124. Notification(Throw, TeamID);
  125. }
  126.  
  127. public void add1ToA(View v){
  128. Throw=1;
  129. ThrowA = ThrowA +1;
  130. TeamID = "Team A";
  131. RandomizeThrow(Throw,TeamID);
  132. ScoreA = ScoreA +Throw;
  133. displayScoreA(ScoreA);
  134. Notification(Throw, TeamID);
  135. }
  136.  
  137. public void add3ToB(View v){
  138. Throw=3;
  139. ThrowB = ThrowB +1;
  140. TeamID = "Team B";
  141. RandomizeThrow(Throw,TeamID);
  142. ScoreB = ScoreB +Throw;
  143. displayScoreB(ScoreB);
  144. Notification(Throw, TeamID);
  145. }
  146.  
  147. public void add2ToB(View v){
  148. Throw = 2;
  149. ThrowB = ThrowB +1;
  150. TeamID = "Team B";
  151. RandomizeThrow(Throw,TeamID);
  152. ScoreB = ScoreB +Throw;
  153. displayScoreB(ScoreB);
  154. Notification(Throw, TeamID);
  155. }
  156.  
  157. public void add1ToB(View v){
  158. Throw=1;
  159. ThrowB = ThrowB +1;
  160. TeamID = "Team B";
  161. RandomizeThrow(Throw,TeamID);
  162. ScoreB = ScoreB +Throw;
  163. displayScoreB(ScoreB);
  164. Notification(Throw, TeamID);
  165. }
  166.  
  167. int RandomizeThrow(int RandomResult, String TeamID)
  168. {
  169. int min=0;
  170. int max=100;
  171.  
  172. Random ran = new Random();
  173. if(ran != null) {
  174.  
  175. if (Throw == 2) {
  176. int ran2 = (ran.nextInt(max - min + 1));
  177. if (ran2 < 50) {
  178. Throw = 2;
  179. } else {
  180. Throw = 0;
  181. if (TeamID == "Team B") {
  182. MissedThrowB = MissedThrowB + 1;
  183. }
  184. if (TeamID == "Team A"){
  185. MissedThrowA = MissedThrowA + 1;
  186. }
  187. }
  188. }
  189. if (Throw == 3) {
  190. int ran3 = (ran.nextInt(max - min+1));
  191. if (ran3 < 25) {
  192. Throw = 3;
  193. } else {
  194. Throw = 0;
  195. if(TeamID == "Team B"){
  196. MissedThrowB = MissedThrowB+1;
  197. }
  198. if (TeamID == "Team A"){
  199. MissedThrowA = MissedThrowA+1;
  200. }
  201. }
  202. }
  203. if (Throw == 1) {
  204. int ran1 = (ran.nextInt(max - min+1));
  205. if (ran1 < 75) {
  206. Throw = 1;
  207. }
  208. if (ran1 >= 75){
  209. Throw = 0;
  210. if(TeamID == "Team B"){
  211. MissedThrowB = MissedThrowB+1;
  212. }
  213. if (TeamID == "Team A"){
  214. MissedThrowA = MissedThrowA+1;
  215. }
  216. }
  217. }
  218. }
  219. accuracy(MissedThrowA,MissedThrowB,ThrowA,ThrowB);
  220. return RandomResult;
  221.  
  222. }
  223.  
  224. }
Add Comment
Please, Sign In to add comment