0% found this document useful (0 votes)
3 views8 pages

Androidstdassignment

The document contains Java code for an Android application that implements a simple calculator with addition, subtraction, multiplication, and division functionalities. It includes an XML layout for the user interface, featuring EditText fields for input, buttons for operations, and a TextView for displaying results. The application uses Toast messages to show results and has a clear button to reset inputs.

Uploaded by

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

Androidstdassignment

The document contains Java code for an Android application that implements a simple calculator with addition, subtraction, multiplication, and division functionalities. It includes an XML layout for the user interface, featuring EditText fields for input, buttons for operations, and a TextView for displaying results. The application uses Toast messages to show results and has a clear button to reset inputs.

Uploaded by

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

Java code

package [Link].newapp2122;

import [Link];

import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];

public class MainActivity extends AppCompatActivity {


EditText ed1,ed2;
Button b1,b2,b3,b4,c;
Double n1,n2;
Double n3;

TextView r;
@SuppressLint("MissingInflatedId")
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);

ed1=findViewById([Link].ed1);
ed2=findViewById([Link].ed2);
b1=findViewById([Link].b1);
b2=findViewById([Link].b2);
b3=findViewById([Link].b3);
b4=findViewById([Link].b4);
c=findViewById([Link]);
r=findViewById([Link]);

[Link](new [Link]() {
@Override
public void onClick(View view) {

n1=[Link]([Link]().toString());
n2=[Link]([Link]().toString());
n3=n1+n2;
[Link]([Link](n3));
[Link]([Link], [Link](), Toast.LENGTH_LONG).show();
}
});
[Link](new [Link]() {
@Override
public void onClick(View view) {
n1=[Link]([Link]().toString());
n2=[Link]([Link]().toString());
n3=n1-n2;
[Link]([Link](n3));
[Link]([Link], [Link](), Toast.LENGTH_LONG).show();
}
});

[Link](new [Link]() {
@Override
public void onClick(View view) {
n1=[Link]([Link]().toString());
n2=[Link]([Link]().toString());
n3=n1*n2;
[Link]([Link](n3));
[Link]([Link], [Link](), Toast.LENGTH_LONG).show();
}
});

[Link](new [Link]() {
@Override
public void onClick(View view) {
n1=[Link]([Link]().toString());
n2=[Link]([Link]().toString());
n3=n1/n2;
[Link]([Link](n3));
[Link]([Link], [Link](), Toast.LENGTH_LONG).show();
}
});
[Link](new [Link]() {
@Override
public void onClick(View view) {
[Link]("");
[Link]("");
[Link]("");

}
});
}
}

xml code
<?xml version="1.0" encoding="utf-8"?>
<[Link]
xmlns:android="[Link]
xmlns:app="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#4C4A4A"
tools:context=".MainActivity">

<TextView
android:id="@+id/calculator"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="28dp"
android:fontFamily="sans-serif-smallcaps"
android:shadowColor="#E4CFCF"
android:text="CALCULATOR"
android:textColor="#D3CFCF"
android:textColorHighlight="#F6E7E7"
android:textColorHint="#EFEEEE"
android:textColorLink="#CDBEBE"
android:textSize="40sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.503"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<EditText
android:id="@+id/ed1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="36dp"
android:ems="10"
android:hint="Enter the first Number"
android:inputType="text"
android:minHeight="48dp"
android:textColor="#DCDCD6"
android:textColorHint="#878786"
app:layout_constraintBottom_toTopOf="@+id/ed2"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.48"
app:layout_constraintStart_toStartOf="parent" />

<EditText
android:id="@+id/ed2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="112dp"
android:ems="10"
android:hint="Enter the second Number"
android:inputType="text"
android:textColor="#DCDCD6"
android:textColorHint="#878786"
app:layout_constraintBottom_toTopOf="@+id/b1"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.48"
app:layout_constraintStart_toStartOf="parent"
tools:ignore="TouchTargetSizeCheck" />

<Button
android:id="@+id/b1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="39dp"
android:layout_marginBottom="233dp"
android:backgroundTint="#EDE2E2"
android:text="ADD"
android:textColor="#0E0E0E"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent" />

<Button
android:id="@+id/b2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="14dp"
android:backgroundTint="#EDE2E2"
android:text="SUB"
android:textColor="#0E0E0E"
app:layout_constraintStart_toStartOf="@+id/b1"
app:layout_constraintTop_toBottomOf="@+id/b1" />

<Button
android:id="@+id/b3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:backgroundTint="#EDE2E2"
android:text="MUL"
android:textColor="#0E0E0E"
app:layout_constraintStart_toStartOf="@+id/b2"
app:layout_constraintTop_toBottomOf="@+id/b2" />

<Button
android:id="@+id/b4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="17dp"
android:backgroundTint="#EDE2E2"
android:text="DIV"
android:textColor="#0E0E0E"
app:layout_constraintStart_toStartOf="@+id/b3"
app:layout_constraintTop_toBottomOf="@+id/b3" />

<Button
android:id="@+id/clear"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="71dp"
android:layout_marginBottom="143dp"
android:backgroundTint="#EDE2E2"
android:text="Clear"
android:textColor="#0E0E0E"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />

<TextView
android:id="@+id/res"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="44dp"
android:hint="Result"
android:textColor="#DCDCD6"
android:textColorHint="#878786"
app:layout_constraintStart_toStartOf="@+id/ed2"
app:layout_constraintTop_toBottomOf="@+id/ed2" />

</[Link]>

Design.
Output.

You might also like