0% found this document useful (0 votes)
13 views

SrNo 9

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views

SrNo 9

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

<?xml version="1.0" encoding="utf-8"?

>
<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<EditText
android:id="@+id/et1"
android:layout_width="80dp"
android:layout_height="wrap_content"
android:layout_x="75dp"
android:inputType="number"
android:layout_y="77dp" />

<EditText
android:id="@+id/et2"
android:layout_width="80dp"
android:layout_height="wrap_content"
android:layout_x="209dp"
android:inputType="number"
android:layout_y="77dp"/>

<TextView
android:id="@+id/tvanswer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="82dp"
android:layout_y="175dp"
android:text=" " />

<Button
android:id="@+id/add"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="97dp"
android:layout_y="239dp"
android:text=" + " />

<Button
android:id="@+id/sub"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="220dp"
android:layout_y="239dp"
android:text=" - " />

<Button
android:id="@+id/mul"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="96dp"
android:layout_y="301dp"
android:text=" * " />

<Button
android:id="@+id/div"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="222dp"
android:layout_y="301dp"
android:text=" / " />

<Button
android:id="@+id/calc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="158dp"
android:layout_y="362dp"
android:text=" = " />
</AbsoluteLayout>

package com.example.demopra;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import java.lang.reflect.Array;

public class MainActivity extends AppCompatActivity {

EditText et1,et2;
Button add,sub,mul,div,calc;
TextView tvanswer;
@Override
protected void onCreate(Bundle savedInstancestate){
super.onCreate(savedInstancestate);
setContentView(R.layout.activity_main);
et1 = (EditText) findViewById(R.id.et1);
et2 = (EditText) findViewById(R.id.et2);
add = (Button) findViewById(R.id.add);
sub = (Button) findViewById(R.id.sub);
mul = (Button) findViewById(R.id.mul);
div = (Button) findViewById(R.id.div);
tvanswer = (TextView) findViewById(R.id.tvanswer);

add.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int no1 = Integer.parseInt(et1.getText().toString());
int no2 = Integer.parseInt(et2.getText().toString());
tvanswer.setText("Addition= "+(no1+no2));
}
});
sub.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int no1 = Integer.parseInt(et1.getText().toString());
int no2 = Integer.parseInt(et2.getText().toString());
tvanswer.setText("Substraction = "+(no1-no2));
}
});
mul.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int no1 = Integer.parseInt(et1.getText().toString());
int no2 = Integer.parseInt(et2.getText().toString());
tvanswer.setText("Multiplication = "+(no1*no2));
}
});
div.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int no1 = Integer.parseInt(et1.getText().toString());
int no2 = Integer.parseInt(et2.getText().toString());
tvanswer.setText("Division = "+(no1/no2));
}
});

You might also like