-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainActivity.java
More file actions
117 lines (93 loc) · 4.47 KB
/
MainActivity.java
File metadata and controls
117 lines (93 loc) · 4.47 KB
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
package com.example.samplecalculator;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
EditText No1, No2;
TextView No3;
Button B1, B2, B3, B4;
Double n1,n2,n3;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
No1= findViewById(R.id.Number1Edit);
No2= findViewById(R.id.Number2Edit);
No3= findViewById(R.id.ResultText);
B1= findViewById(R.id.Addbtn);
B2= findViewById(R.id.Subbtn);
B3= findViewById(R.id.Mulbtn);
B4= findViewById(R.id.Divbtn);
// when we will click on the Button 1 which is for Addition
B1.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View view)
{
if ((No1.getText().length() > 0) && (No2.getText().length() > 0))
{
n1 = Double.parseDouble(No1.getText().toString()); // the No1 value which is string is converted into the double for addition
n2 = Double.parseDouble(No2.getText().toString()); // the No2 value which is string is converted into the double for additi
n3 = n1 + n2; // Addition of No1 and No2
No3.setText(String.valueOf(n3)); // n3 is double value which is converted into the double for addition
}
else{
String result = "Please Enter the correct details";
No3.setText(result);
}
; }
});
B2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if ((No1.getText().length() > 0) && (No2.getText().length() > 0))
{
n1 = Double.parseDouble(No1.getText().toString()); // the No1 value which is string is converted into the double for addition
n2 = Double.parseDouble(No2.getText().toString()); // the No2 value which is string is converted into the double for additi
n3 = n1 - n2; // Addition of No1 and No2
No3.setText(String.valueOf(n3)); // n3 is double value which is converted into the double for addition
}
else{
String result = "Please Enter the correct details";
No3.setText(result);
}
}
});
B3.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if ((No1.getText().length() > 0) && (No2.getText().length() > 0))
{
n1 = Double.parseDouble(No1.getText().toString()); // the No1 value which is string is converted into the double for addition
n2 = Double.parseDouble(No2.getText().toString()); // the No2 value which is string is converted into the double for additi
n3 = n1 * n2; // Addition of No1 and No2
No3.setText(String.valueOf(n3)); // n3 is double value which is converted into the double for addition
}
else{
String result = "Please Enter the correct details";
No3.setText(result);
}
}
});
B4.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if ((No1.getText().length() > 0) && (No2.getText().length() > 0))
{
n1 = Double.parseDouble(No1.getText().toString()); // the No1 value which is string is converted into the double for addition
n2 = Double.parseDouble(No2.getText().toString()); // the No2 value which is string is converted into the double for additi
n3 = n1 / n2; // Addition of No1 and No2
No3.setText(String.valueOf(n3)); // n3 is double value which is converted into the double for addition
}
else{
String result = "Please Enter the correct details";
No3.setText(result);
}
}
});
}
}