1 Calculator

You might also like

Download as pdf
Download as pdf
You are on page 1of 3
File - C:\Userslariun\Desktop\BMS\2ND SEMIMAD\AndroidStudioProjectsIMyBasicCalApplicationiappisrcimainjavalcomiexam 1 package com.example.mybasiccalapplication; 2 3 4 5 6 7 8 9 16 a 12 13 14 15 16 a7 1s 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 49 41 42 43 44 45 import import import import import import import. public androidx.appcompat .app.AppCompatActivity; android.os.Bundle; android. view. View; android.widget Button; android.widget .EditText; android.widget.TextView; android.widget. Toast; class MainActivity extends AppCompatActivity { EditText op1,0p2; Button btnadd, btnsub, btnmul, btndiv, btneLn; TextView txtresult; @override protected void onCreate(Bundle savedInstanceState) { super. onCreate(savedInstanceState) ; setContentView(R. Layout. activity_main) ; op1=(EditText) findViewById(R.id.op1); EditText) findViewById(R.id.op2); Button) findViewByld(R.id.add) ; Button) findViewById(R. id. sub); Button) findViewByld(R.id.mul) ; Button) findViewById(R. id. div) ; btnelr=(Button) findViewById(R.id.clr); txtresult=(TextView) findViewById(R.id.result); btnadd.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if(op1.getText().Length()>0&&op2.getText(). Length()>0) { double oper1=Double.parseDouble(op1.getText ©. tostring()); double oper2=Double.parseDouble(op2.getText ©. tostring()); double resuLt=oper1+oper2; txtresult.setText (Double. toString(result)); } else { Page 1 of3 File - C:\Userslariun\Desktop\BMS\2ND SEMIMAD\AndroidStudioProjectsIMyBasicCalApplicationiappisrcimainjavalcomiexam 46 Toast .makeText (MainActivity. this, "Enter required Number", Toast.LENGTH_LONG) .show() ; 47 } 48 + 49 Hi 50 51 btnsub.setOnClickListener(new View.OnClickListener() { 52 Q0verride 53 public void onClick(View view) { 54 if(op1.getText() . length()>0&&op2.getText(). Length()>0) 55 { 56 double oper1=Double.parseDouble(op1.getText ©. tostring()); 87 double oper2=Double.parseDouble(op2.getText ©. tostring()); 58 double result-opert-oper2; 59 60 txtresult.setText (Double. toString(result)); 61 } 62 else { 63 Toast.makeText (MainActivity. this, "Enter required Number", Toast.LENGTH_LONG). show() ; 64 + 65 t 66 ni; 67 68 btnmul.setOnClickListener(new View.OnClickListener() { 69 Q@override 79 public void onClick(View view) { m1 if(op1.getText().Length()>0&&op2.getText(). ‘Length()>0) 72 { 73 double oper1=Double.parseDouble(op1.getText Q.tostring(); 14 double oper2=Double.parseDouble(op2.getText ©. toString()); 15 double result=operi*oper2; 16 17 txtresult.setText (Double. toString (result)) ; 78 } 19 else { 80 Toast. makeText (MainActivity. this, "Enter required Number", Toast.LENGTH_LONG) . show() ; 81 } 82 + 83 Yi 84 Page 2013 File - :\Userslariun\Desktop\BMS\2ND SEMIMAD\AndroidStudioProjects|MyBasicCalApplicationiappisrcimainjavalcomiexam 85 btndiv. setOnClickListener (new View.OnClickListener() { 86 @Override 87 public void onClick(View view) { 88 if(op1.getText().Length()>0&s0p2.getText() . ‘Length ()>0) 89 t 99 double oper1=Double.parseDouble(op1. getText().toString()); 1 double oper2=Double.parseDouble(op2. getText().toString()); 92 double result=opert/oper2; 93 94 txtresult.setText (Double. toString(result. YD: 95 + 96 else { 97 Toast .makeText (NainActivity.this, "Enter required Number", Toast.LENGTH_LONG) .show(); 98 } 99 + 190 vi 191 102 btnelr.setOnClickListener(new View.OnClickListener() { 103 @Override 104 public void onClick(View view) { 105 op1.setText(""); 106 op2.setText(""); 107 op1.requestFocus(); 108 txtresult. setText("9.00") ; 109 110 + an vi 112 113 i 114 } Page 3 of3

You might also like