java code for calculater
//java code for calculater +, -, *, /,
package com.rafiqhussain.rafiqcalculater;
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 {
//inshlaiz ابتدا
// field or vareble diclarerion
EditText etFirtsvalue , edSecondValue;
TextView tvAns;
Button add, sub, multyply, divide;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// (xml item's k ID's) ko find kar k variable (etFirtsvalue ) sy band dia jor kia gia...
etFirtsvalue = findViewById(R.id.et_1);//is main user jo value dega us ko ham sy integer main badalna hoga line 51 main +-/* ko karny k liy nahi to nahi hoga.
edSecondValue = findViewById(R.id.et_2);
tvAns = findViewById(R.id.tvAns);
add = findViewById(R.id.btnAdd);
sub = findViewById(R.id.btnSub);
multyply = findViewById(R.id.btnMulti);
divide = findViewById(R.id.btnDivid);
//is line sy (Ans is =) pehle sy show hoga (textView) main
tvAns.setText("Ans is =");
// yahan par functions kia sab cheezon ko
add.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
//yahan sy function shoro hoga.
/*jo value user enter karta hy us ko string main badalna hoga string main
badalny ky k baad is ko integer main badal sakty hain*/
/*
isliy ham int datatype ka 3 varible banay gy
name hoga --firstValue , second Value , ans;--
*/
int firstValue , secondValue , ans;
//hamry 1st and 2nd value intger main badal gai
firstValue = Integer.parseInt(etFirtsvalue.getText().toString());
secondValue = Integer.parseInt(edSecondValue.getText().toString());
//is line k main 1st and 2nd Value ko plus hojay ga
ans = firstValue + secondValue;
// is line main tvAns main Answar sho hojay ga
//"Ans is = "+ k madad sy aap java main text show hojay ga is no (cocatinat) bolty hain
tvAns.setText("Ans is = "+ans);
}
});
sub.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
//yahan sy function shoro hoga.
/*jo value user enter karta hy us ko string main badalna hoga string main
badalny ky k baad is ko integer main badal sakty hain*/
/*
isliy ham int datatype ka 3 varible banay gy
name hoga --firstValue , second Value , ans;--
*/
int firstValue , secondValue , ans;
//hamry 1st and 2nd value intger main badal gai
firstValue = Integer.parseInt(etFirtsvalue.getText().toString());
secondValue = Integer.parseInt(edSecondValue.getText().toString());
//is line k main 1st and 2nd Value ko plus hojay ga
ans = firstValue - secondValue;
// is line main tvAns main Answar sho hojay ga
//"Ans is = "+ k madad sy aap java main text show hojay ga is no (cocatinat) bolty hain
tvAns.setText("Ans is = "+ ans);
}
});
multyply.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
//yahan sy function shoro hoga.
/*jo value user enter karta hy us ko string main badalna hoga string main
badalny ky k baad is ko integer main badal sakty hain*/
/*
isliy ham int datatype ka 3 varible banay gy
name hoga --firstValue , second Value , ans;--
*/
int firstValue , secondValue , ans;
//hamry 1st and 2nd value intger main badal gai
firstValue = Integer.parseInt(etFirtsvalue.getText().toString());
secondValue = Integer.parseInt(edSecondValue.getText().toString());
//is line k main 1st and 2nd Value ko plus hojay ga
ans = firstValue * secondValue;
// is line main tvAns main Answar sho hojay ga
//"Ans is = "+ k madad sy aap java main text show hojay ga is no (cocatinat) bolty hain
tvAns.setText("Ans is = "+ ans);
}
});
divide.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
//yahan sy function shoro hoga.
/*jo value user enter karta hy us ko string main badalna hoga string main
badalny ky k baad is ko integer main badal sakty hain*/
/*
isliy ham int datatype ka 3 varible banay gy
name hoga --firstValue , second Value , ans;--
*/
int firstValue , secondValue , ans;
//hamry 1st and 2nd value intger main badal gai
firstValue = Integer.parseInt(etFirtsvalue.getText().toString());
secondValue = Integer.parseInt(edSecondValue.getText().toString());
//is line k main 1st and 2nd Value ko plus hojay ga
ans = firstValue / secondValue;
// is line main tvAns main Answar sho hojay ga
//"Ans is = "+ k madad sy aap java main text show hojay ga is no (cocatinat) bolty hain
tvAns.setText("Ans is = "+ ans);
}
});
//is line sy oopar wala actionBar hide hojay ga..
getSupportActionBar().hide();
}
}
Comments
Post a Comment