0% found this document useful (0 votes)
4 views6 pages

5 Calculator App

The document outlines the design and implementation of a Calculator Application using Android's XML layout and Java code. It includes user interface components like EditText for input, TextView for displaying results, and Buttons for performing arithmetic operations. The application has been designed and verified successfully, producing the expected output.

Uploaded by

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

5 Calculator App

The document outlines the design and implementation of a Calculator Application using Android's XML layout and Java code. It includes user interface components like EditText for input, TextView for displaying results, and Buttons for performing arithmetic operations. The application has been designed and verified successfully, producing the expected output.

Uploaded by

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

Experiment – 5

Aim  Develop Calculator Application.

Designer Code

<RelativeLayout
android:gravity="center"
android:background="@drawable/background1"

<TextView
android:id="@+id/heading"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="CALCULATOR APP!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:textColor="@color/white"
android:background="#75280A"
android:textSize="35dp"
android:layout_margin="40dp"
android:padding="10dp"

/>
<EditText
android:id="@+id/ed1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/heading"
android:hint="First Number"
android:textColor="@color/white"
android:textStyle="bold"
android:layout_margin="10dp"
android:padding="10dp"
android:textColorHint="@color/white"
android:textSize="25dp"
/>
<EditText
android:id="@+id/ed2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/ed1"
android:hint="Second Number"
android:textColor="@color/white"
android:textStyle="bold"
android:layout_margin="10dp"
android:padding="10dp"
android:textColorHint="@color/white"
android:textSize="25dp"
/>
<TextView
android:id="@+id/result"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/ed2"
android:layout_margin="10dp"
android:padding="10dp"
android:text="Result"
android:textSize="25dp"
android:textColor="@color/white"

/>
<Button
android:id="@+id/btnadd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ADD"
android:textSize="25dp"
android:layout_below="@id/result"
android:layout_centerHorizontal="true"
android:layout_margin="5dp"
android:padding="5dp"
/>

<Button
android:id="@+id/btnsub"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="SUB"
android:textSize="25dp"
android:layout_below="@id/btnadd"
android:layout_centerHorizontal="true"
android:layout_margin="5dp"
android:padding="5dp"
/>
<Button
android:id="@+id/btnmul"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="MUL"
android:textSize="25dp"
android:layout_below="@id/btnsub"
android:layout_centerHorizontal="true"
android:layout_margin="5dp"
android:padding="5dp"
/>
<Button
android:id="@+id/btndiv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="DIV"
android:textSize="25dp"
android:layout_below="@id/btnmul"
android:layout_centerHorizontal="true"
android:layout_margin="5dp"
android:padding="5dp"
/>
</RelativeLayout>
JAVA PROGRAM -- >

public class MainActivity extends AppCompatActivity {


EditText et1,et2;
TextView result;
Button btnadd, btnsub, btnmul,btndiv;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
EdgeToEdge.enable(this);
setContentView(R.layout.activity_main);
et1 = (EditText) findViewById(R.id.ed1);
et2 = (EditText) findViewById(R.id.ed2);
result = (TextView) findViewById(R.id.result);
btnadd = (Button) findViewById(R.id.btnadd);
btnsub = (Button) findViewById(R.id.btnsub);
btnmul = (Button) findViewById(R.id.btnmul);
btndiv = (Button) findViewById(R.id.btndiv);

btnadd.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int a,b,c;
a = Integer.parseInt(et1.getText().toString());
b = Integer.parseInt(et2.getText().toString());
c = a + b;
result.setText("Result : " +String.valueOf(c));

}
});

btnsub.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int a,b,c;
a = Integer.parseInt(et1.getText().toString());
b = Integer.parseInt(et2.getText().toString());
c = a - b;
result.setText("Result : " +String.valueOf(c));
}
});

btnmul.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
float a,b,c;
a = Float.parseFloat (et1.getText().toString());
b = Float.parseFloat(et2.getText().toString());
c = a * b;
result.setText("Result : " +String.valueOf(c));
}
});

btndiv.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int a,b,c;
a = Integer.parseInt(et1.getText().toString());
b = Integer.parseInt(et2.getText().toString());
c = a / b;
result.setText("Result : " +String.valueOf(c));
}
});

}
}
Program Output 

Result  Calculator Application is Designed and Verified.

You might also like