-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkotlincode
140 lines (133 loc) · 3.86 KB
/
kotlincode
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.View
import android.widget.Button
import android.widget.EditText
import androidx.appcompat.widget.ViewUtils
import kotlinx.android.synthetic.main.activity_main.*
class MainActivity : AppCompatActivity(),View.OnClickListener {
lateinit var button:Array<Array<Button>>
var res1:Float=-1F
var res2:Float=-1F
var add:Boolean=false
var mul:Boolean=false
var div:Boolean=false
var min:Boolean=false
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
button= arrayOf(arrayOf(btn1,btn2,btn3,btndiv),
arrayOf(btn4,btn5,btn6,btneq),
arrayOf(btn7,btn8,btn9,btnpt),
arrayOf(btn0,btnadd,btnmul),
arrayOf(btnclr,btnmin)
)
buttoninitialise()
for(i in button)
{
for(b in i)
{
b.setOnClickListener(this)
}
}
}
fun buttoninitialise()
{
for(i in button)
{
for(b in i)
{
b.isEnabled=true
}
}
}
override fun onClick(v: View) {
when(v.id)
{
R.id.btn1->{
edt.setText(edt.text.toString()+"1")
}
R.id.btn2->{
edt.setText(edt.text.toString()+"2")
}
R.id.btn3->{
edt.setText(edt.text.toString()+"3")
}
R.id.btn4->{
edt.setText(edt.text.toString()+"4")
}
R.id.btn5->{
edt.setText(edt.text.toString()+"5")
}
R.id.btn6->{
edt.setText(edt.text.toString()+"6")
}
R.id.btn7->{
edt.setText(edt.text.toString()+"7")
}
R.id.btn8->{
edt.setText(edt.text.toString()+"8")
}
R.id.btn9->{
edt.setText(edt.text.toString()+"9")
}
R.id.btn0->{
edt.setText(edt.text.toString()+"0")
}
R.id.btndiv->{
res1=edt.text.toString().toFloat()
edt.setText("")
div=true
}
R.id.btnadd->{
res1=edt.text.toString().toFloat()
edt.setText("")
add=true
}
R.id.btnmin->{
res1=edt.text.toString().toFloat()
edt.setText("")
min=true
}
R.id.btnmul->{
res1=edt.text.toString().toFloat()
edt.setText("")
mul=true
}
R.id.btneq->{
res2=edt.text.toString().toFloat()
if(add==true)
{
var fres:Float=res1+res2
edt.setText(fres.toString())
add=false;
}
else if(min==true)
{
var fres:Float=res1-res2
edt.setText(fres.toString())
min=false;
}
else if(mul==true)
{
var fres:Float=res1*res2
edt.setText(fres.toString())
mul=false;
}
else if(div==true)
{
var fres:Float=res1/res2
edt.setText(fres.toString())
div=false;
}
}
R.id.btnclr->{
edt.setText("")
div=false;
add=false;
mul=false;
min=false;
}
}
}
}