MainActivity.java:

package com.example.appone;

import android.content.Intent;
import android.os.Bundle;
import android.widget.Button;
import android.widget.EditText;

import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {

    EditText etEmpId, etEmpName, etSalary;
    Button btnSubmit;

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        etEmpId = findViewById(R.id.etEmpId);
        etEmpName = findViewById(R.id.etEmpName);
        etSalary = findViewById(R.id.etSalary);
        btnSubmit = findViewById(R.id.btnSubmit);

        btnSubmit.setOnClickListener(v -> {

            String id = etEmpId.getText().toString();
            String name = etEmpName.getText().toString();

            String salaryText = etSalary.getText().toString().trim();

            if (salaryText.isEmpty()) {
                etSalary.setError("Enter basic salary");
                etSalary.requestFocus();
                return;
            }

            double salary = Double.parseDouble(salaryText);

            double hra = salary * 0.20;
            double da = salary * 0.10;
            double total = salary + hra + da;

            Intent intent =

                    new Intent(
                            MainActivity.this,
                            SecondActivity.class);
            intent.putExtra("id", id);
            intent.putExtra("name", name);
            intent.putExtra("salary", salary);
            intent.putExtra("hra", hra);
            intent.putExtra("da", da);
            intent.putExtra("total", total);

            startActivity(intent);
        });
    }
}


activity_main.xml:

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

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:padding="20dp"
    android:gravity="center_vertical">

    <EditText
        android:id="@+id/etEmpId"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="Enter Employee ID"/>

    <EditText
        android:id="@+id/etEmpName"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="Enter Employee Name"
        android:layout_marginTop="10dp"/>

    <EditText
        android:id="@+id/etSalary"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="Enter Basic Salary"
        android:inputType="number"
        android:layout_marginTop="10dp"/>

    <Button
        android:id="@+id/btnSubmit"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="CALCULATE AND SHOW DETAILS"
        android:layout_marginTop="20dp"/>

</LinearLayout>


SecondActivity.java:

package com.example.appone;

import android.os.Bundle;
import android.widget.Button;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;

public class SecondActivity extends AppCompatActivity {

    TextView txtDetails;
    Button btnBack;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_second);

        txtDetails = findViewById(R.id.txtDetails);
        btnBack = findViewById(R.id.btnBack);

        String id = getIntent().getStringExtra("id");
        String name = getIntent().getStringExtra("name");

        double salary =
                getIntent().getDoubleExtra(
                        "salary", 0);

        double hra =
                getIntent().getDoubleExtra(
                        "hra", 0);

        double da =
                getIntent().getDoubleExtra(
                        "da", 0);

        double total =
                getIntent().getDoubleExtra(
                        "total", 0);

        txtDetails.setText(
                "EMPLOYEE DETAILS\n\n" +
                        "ID: " + id +
                        "\n\nName: " + name +
                        "\n\nBasic Salary: ₹" + salary +
                        "\n\nHRA (20%): ₹" + hra +
                        "\n\nDA (10%): ₹" + da +
                        "\n\nTotal Salary: ₹" + total
        );

        btnBack.setOnClickListener(v -> finish());
    }
}


activity_second.xml:

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

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:gravity="center"
    android:padding="20dp">

    <TextView
        android:id="@+id/txtDetails"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="18sp"/>

    <Button
        android:id="@+id/btnBack"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="BACK"
        android:layout_marginTop="20dp"/>

</LinearLayout>


AndroidManifest.xml:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools">

    <application
        android:allowBackup="true"
        android:dataExtractionRules="@xml/data_extraction_rules"
        android:fullBackupContent="@xml/backup_rules"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/Theme.Appone">
        <activity
            android:name=".MainActivity"
            android:exported="true"
            android:windowSoftInputMode="adjustResize">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name=".SecondActivity"
            android:exported="false" />
    </application>
</manifest>
