-
Notifications
You must be signed in to change notification settings - Fork 1
/
MainActivity.java
101 lines (83 loc) · 2.62 KB
/
MainActivity.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
package com.example.android.ipl2018;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
public int scoreTeamA;
public int scoreTeamB;
TextView scoreViewA;
TextView scoreViewB;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
scoreViewA = findViewById(R.id.team_a_score);
scoreViewB = findViewById(R.id.team_b_score);
}
//Displays the given score for Team A.
public void addOnePointsToA(View v) {
scoreTeamA ++ ;
displayForTeamA(scoreTeamA);
}
public void addTwoPointsToA(View v) {
scoreTeamA +=2 ;
displayForTeamA(scoreTeamA);
}
public void addFourPointsToA(View v) {
scoreTeamA +=4;
displayForTeamA(scoreTeamA);
}
public void addSixPointsToA(View v) {
scoreTeamA +=6;
displayForTeamA(scoreTeamA);
}
//**display the score of team b//
public void addOnePointsToB(View v) {
scoreTeamB ++ ;
displayForTeamB(scoreTeamB);
}
public void addTwoPointsToB(View v) {
scoreTeamB +=2;
displayForTeamB(scoreTeamB);
}
public void addFourPointsToB(View v) {
scoreTeamB +=4;
displayForTeamB(scoreTeamB);
}
public void addSixPointsToB(View v) {
scoreTeamB +=6;
displayForTeamB(scoreTeamB);
}
//Reset score//
public void reset_team_a_and_b(View v) {
scoreTeamA = 0;
scoreTeamB = 0;
displayForTeamA(scoreTeamA);
displayForTeamB(scoreTeamB);
}
// Display score for team A //
public void displayForTeamA(int scoreTeamA) {
scoreViewA.setText(String.valueOf(scoreTeamA));
}
// Display score for team B //
public void displayForTeamB(int scoreTeamB) {
scoreViewB.setText(String.valueOf(scoreTeamB));
}
//data save after rotation//
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putInt("countA", scoreTeamA);
outState.putInt("countB", scoreTeamB);
}
// data restore //
@Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
super.onRestoreInstanceState(savedInstanceState);
scoreTeamA = savedInstanceState.getInt("countA");
scoreTeamB = savedInstanceState.getInt("countB");
displayForTeamA(scoreTeamA);
displayForTeamB(scoreTeamB);
}
}