package com.example.newbee; import androidx.appcompat.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.*; public class MainActivity extends AppCompatActivity { Button add, sub, mul, div; TextView txt1, txt2; EditText a,b; TextView resv; Double num1; Double num2; Double res; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); add = findViewById(R.id.ad); sub = findViewById(R.id.sub); mul = findViewById(R.id.mul); div = findViewById(R.id.div); a = findViewById(R.id.num1); b = findViewById(R.id.num2); resv = findViewById(R.id.res); add.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { num1 = Double.parseDouble(a.getText().toString()); num2 = Double.parseDouble(b.getText().toString()); res = num1+num2; resv.setText(res.toString()); } }); sub.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { num1 = Double.parseDouble(a.getText().toString()); num2 = Double.parseDouble(b.getText().toString()); res = num1-num2; resv.setText(res.toString()); } }); mul.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { num1 = Double.parseDouble(a.getText().toString()); num2 = Double.parseDouble(b.getText().toString()); res = num1*num2; resv.setText(res.toString()); } }); div.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { num1 = Double.parseDouble(a.getText().toString()); num2 = Double.parseDouble(b.getText().toString()); res = num1/num2; resv.setText(res.toString()); } }); } }