package com.example.cal049; 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; public class MainActivity extends AppCompatActivity implements View.OnClickListener { Button but_add; Button but_sub; Button but_div; Button but_mul; EditText but_num1,but_num2; TextView res; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); but_add=(Button) findViewById(R.id.add); but_sub=(Button) findViewById(R.id.sub); but_div=(Button) findViewById(R.id.div); but_mul=(Button) findViewById(R.id.mul); but_num1=(EditText) findViewById(R.id.num1); but_num2=(EditText) findViewById(R.id.num2); res=(TextView) findViewById(R.id.result); but_add.setOnClickListener(this); but_sub.setOnClickListener(this); but_div.setOnClickListener(this); but_mul.setOnClickListener(this); } @Override public void onClick(View v) { double op1=Double.parseDouble(but_num1.getText().toString()); double op2=Double.parseDouble(but_num2.getText().toString()); double text_res = 0; if(v.equals(but_add)) text_res=op1+op2; else if(v.equals(but_sub)) text_res=op1-op2; else if(v.equals(but_div)) text_res=op1/op2; else if(v.equals(but_mul)) text_res=op1*op2; else text_res=0; res.setText(String.valueOf(text_res)); } }