-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcalculator.java
More file actions
52 lines (45 loc) · 2.05 KB
/
Copy pathcalculator.java
File metadata and controls
52 lines (45 loc) · 2.05 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
package com.example.myapplication;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void addClick(View v){
EditText number1 = (EditText) findViewById(R.id.number1);
EditText number2 = (EditText) findViewById(R.id.number2);
TextView result = (TextView) findViewById(R.id.result);
int n1 = Integer.parseInt(number1.getText().toString());
int n2 = Integer.parseInt(number2.getText().toString());
result.setText(Integer.toString(n1 + n2));
}
public void subClick(View v){
EditText number1 = (EditText) findViewById(R.id.number1);
EditText number2 = (EditText) findViewById(R.id.number2);
TextView result = (TextView) findViewById(R.id.result);
int n1 = Integer.parseInt(number1.getText().toString());
int n2 = Integer.parseInt(number2.getText().toString());
result.setText(Integer.toString(n1 - n2));
}
public void mulClick(View v){
EditText number1 = (EditText) findViewById(R.id.number1);
EditText number2 = (EditText) findViewById(R.id.number2);
TextView result = (TextView) findViewById(R.id.result);
int n1 = Integer.parseInt(number1.getText().toString());
int n2 = Integer.parseInt(number2.getText().toString());
result.setText(Integer.toString(n1 * n2));
}
public void divClick(View v){
EditText number1 = (EditText) findViewById(R.id.number1);
EditText number2 = (EditText) findViewById(R.id.number2);
TextView result = (TextView) findViewById(R.id.result);
int n1 = Integer.parseInt(number1.getText().toString());
int n2 = Integer.parseInt(number2.getText().toString());
result.setText(Integer.toString(n1 / n2));
}
}