MainActivity.java:

package com.example.appone;

import android.content.Intent;
import android.os.Bundle;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Toast;
import android.view.Menu;
import android.view.MenuItem;

import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {

    EditText etName, etRegNo;
    RadioGroup rgMembership;
    RadioButton rbRegular, rbPremium;
    CheckBox cbJava, cbPython, cbAndroid, cbDatabase;
    Button btnBorrow;

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

        etName = findViewById(R.id.etName);
        etRegNo = findViewById(R.id.etRegNo);

        rgMembership = findViewById(R.id.rgMembership);
        rbRegular = findViewById(R.id.rbRegular);
        rbPremium = findViewById(R.id.rbPremium);

        cbJava = findViewById(R.id.cbJava);
        cbPython = findViewById(R.id.cbPython);
        cbAndroid = findViewById(R.id.cbAndroid);
        cbDatabase = findViewById(R.id.cbDatabase);

        btnBorrow = findViewById(R.id.btnBorrow);

        btnBorrow.setOnClickListener(v -> {

            String name = etName.getText().toString().trim();
            String regNo = etRegNo.getText().toString().trim();

            if (name.isEmpty()) {
                etName.setError("Enter student name");
                etName.requestFocus();
                return;
            }

            if (regNo.isEmpty()) {
                etRegNo.setError("Enter register number");
                etRegNo.requestFocus();
                return;
            }

            if (rgMembership.getCheckedRadioButtonId() == -1) {
                Toast.makeText(this, "Select membership type",
Toast.LENGTH_SHORT).show();
                return;
            }

            if (!cbJava.isChecked()
                    && !cbPython.isChecked()
                    && !cbAndroid.isChecked()
                    && !cbDatabase.isChecked()) {

                Toast.makeText(this, "Select at least one book",
Toast.LENGTH_SHORT).show();
                return;
            }

            String membership;

            if (rbRegular.isChecked()) {
                membership = "Regular";
            } else {
                membership = "Premium";
            }

            Intent intent = new Intent(MainActivity.this, SummaryActivity.class);



            intent.putExtra("name", name);
            intent.putExtra("regNo", regNo);
            intent.putExtra("membership", membership);

            intent.putExtra("java", cbJava.isChecked());
            intent.putExtra("python", cbPython.isChecked());
            intent.putExtra("android", cbAndroid.isChecked());
            intent.putExtra("database", cbDatabase.isChecked());

            startActivity(intent);
        });
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.menu_main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {

        if (item.getItemId() == R.id.menu_home) {
            Toast.makeText(this, "You are on the Home screen",
                    Toast.LENGTH_SHORT).show();
            return true;
        }

        if (item.getItemId() == R.id.menu_new) {
            recreate();
            return true;
        }

        if (item.getItemId() == R.id.menu_exit) {
            finishAffinity();
            return true;
        }

        return super.onOptionsItemSelected(item);
    }
}


activity_main.xml:

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

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"

    android:layout_height="match_parent">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:padding="20dp">

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="LIBRARY BOOK BORROWING"
            android:textSize="24sp"
            android:textStyle="bold"
            android:textColor="?android:attr/textColorPrimary"
            android:gravity="center"
            android:paddingBottom="20dp" />

        <EditText
            android:id="@+id/etName"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="Student Name"
            android:inputType="textPersonName" />

        <EditText
            android:id="@+id/etRegNo"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp"
            android:hint="Register Number"
            android:inputType="text" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="20dp"
            android:text="Membership Type"
            android:textSize="18sp"
            android:textStyle="bold" />

        <RadioGroup
            android:id="@+id/rgMembership"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content">



            <RadioButton
                android:id="@+id/rbRegular"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Regular" />

            <RadioButton
                android:id="@+id/rbPremium"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Premium" />

        </RadioGroup>

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="15dp"
            android:text="Books to Borrow"
            android:textSize="18sp"
            android:textStyle="bold" />

        <CheckBox
            android:id="@+id/cbJava"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Java - ₹100" />

        <CheckBox
            android:id="@+id/cbPython"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Python - ₹120" />

        <CheckBox
            android:id="@+id/cbAndroid"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Android - ₹150" />

        <CheckBox
            android:id="@+id/cbDatabase"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Database - ₹130" />



        <Button
            android:id="@+id/btnBorrow"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="25dp"
            android:text="BORROW BOOKS" />

    </LinearLayout>

</ScrollView>


SummaryActivity.java:

package com.example.appone;

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

import androidx.appcompat.app.AppCompatActivity;

public class SummaryActivity extends AppCompatActivity {

    TextView tvName, tvRegNo, tvMembership, tvBooks, tvFee;
    Button btnConfirm;

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

        tvName = findViewById(R.id.tvName);
        tvRegNo = findViewById(R.id.tvRegNo);
        tvMembership = findViewById(R.id.tvMembership);
        tvBooks = findViewById(R.id.tvBooks);
        tvFee = findViewById(R.id.tvFee);
        btnConfirm = findViewById(R.id.btnConfirm);
        Intent intent = getIntent();
        String name = intent.getStringExtra("name");
        String regNo = intent.getStringExtra("regNo");
        String membership = intent.getStringExtra("membership");

        boolean hasJava = intent.getBooleanExtra("java", false);
        boolean hasPython = intent.getBooleanExtra("python", false);
        boolean hasAndroid = intent.getBooleanExtra("android", false);

        boolean hasDatabase = intent.getBooleanExtra("database", false);

        StringBuilder books = new StringBuilder();
        double fee = 0;

        if (hasJava) {
            books.append("Java, ");
            fee += 100;
        }

        if (hasPython) {
            books.append("Python, ");
            fee += 120;
        }

        if (hasAndroid) {
            books.append("Android, ");
            fee += 150;
        }

        if (hasDatabase) {
            books.append("Database, ");
            fee += 130;
        }

        if (books.length() > 2) {
            books.delete(books.length() - 2, books.length());
        }
        final double totalFee = fee;
        tvName.setText("Student Name : " + name);
        tvRegNo.setText("Register Number : " + regNo);
        tvMembership.setText("Membership Type : " + membership);
        tvBooks.setText("Books Selected : " + books);
        tvFee.setText("Total Book Fee : ₹" + totalFee);

        btnConfirm.setOnClickListener(v -> {

            Intent invoiceIntent = new Intent(
                    SummaryActivity.this,
                    InvoiceActivity.class
            );

            invoiceIntent.putExtra("name", name);
            invoiceIntent.putExtra("regNo", regNo);
            invoiceIntent.putExtra("membership", membership);
            invoiceIntent.putExtra("books", books.toString());


            invoiceIntent.putExtra("fee", totalFee);

            startActivity(invoiceIntent);
        });
    }
}


activity_summary.xml:

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

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:padding="20dp">

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="BORROWING SUMMARY"
            android:textSize="26sp"
            android:textStyle="bold"
            android:textColor="?android:attr/textColorPrimary"
            android:gravity="center"
            android:paddingBottom="20dp" />

        <TextView
            android:id="@+id/tvName"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textSize="18sp"
            android:padding="8dp" />

        <TextView
            android:id="@+id/tvRegNo"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textSize="18sp"
            android:padding="8dp" />

        <TextView

            android:id="@+id/tvMembership"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textSize="18sp"
            android:padding="8dp" />

        <TextView
            android:id="@+id/tvBooks"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textSize="18sp"
            android:padding="8dp" />

        <TextView
            android:id="@+id/tvFee"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textSize="20sp"
            android:textStyle="bold"
            android:padding="8dp" />

        <Button
            android:id="@+id/btnConfirm"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="25dp"
            android:text="CONFIRM BORROWING" />

    </LinearLayout>

</ScrollView>


InvoiceActivity.java:

package com.example.appone;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
public class InvoiceActivity extends AppCompatActivity {

    TextView tvName, tvRegNo, tvMembership;
    TextView tvBooks, tvFee, tvDiscount, tvFinal;

    @Override
    protected void onCreate(Bundle savedInstanceState) {

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

        tvName = findViewById(R.id.tvName);
        tvRegNo = findViewById(R.id.tvRegNo);
        tvMembership = findViewById(R.id.tvMembership);
        tvBooks = findViewById(R.id.tvBooks);
        tvFee = findViewById(R.id.tvFee);
        tvDiscount = findViewById(R.id.tvDiscount);
        tvFinal = findViewById(R.id.tvFinal);

        Intent intent = getIntent();

        String name = intent.getStringExtra("name");
        String regNo = intent.getStringExtra("regNo");
        String membership = intent.getStringExtra("membership");
        String books = intent.getStringExtra("books");
        double fee = intent.getDoubleExtra("fee", 0);
        double discount = 0;
        if ("Premium".equals(membership)) {
            discount = fee * 0.10;
        }
        double finalAmount = fee - discount;
        tvName.setText("Student Name : " + name);
        tvRegNo.setText("Register Number : " + regNo);
        tvMembership.setText("Membership Type : " + membership);
        tvBooks.setText("Books : " + books);
        tvFee.setText("Book Fee : ₹" + fee);
        tvDiscount.setText("Membership Discount : ₹" + discount);
        tvFinal.setText("Final Amount : ₹" + finalAmount);
    }
}


activity_invoice.xml:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:padding="20dp">


        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="LIBRARY RECEIPT"
            android:textSize="26sp"
            android:textStyle="bold"
            android:textColor="?android:attr/textColorPrimary"
            android:gravity="center"
            android:paddingBottom="20dp" />

        <TextView
            android:id="@+id/tvName"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textSize="18sp"
            android:padding="8dp" />

        <TextView
            android:id="@+id/tvRegNo"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textSize="18sp"
            android:padding="8dp" />

        <TextView
            android:id="@+id/tvMembership"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textSize="18sp"
            android:padding="8dp" />

        <TextView
            android:id="@+id/tvBooks"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textSize="18sp"
            android:padding="8dp" />

        <TextView
            android:id="@+id/tvFee"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textSize="18sp"
            android:padding="8dp" />

        <TextView


            android:id="@+id/tvDiscount"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textSize="18sp"
            android:padding="8dp" />

        <TextView
            android:id="@+id/tvFinal"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textSize="22sp"
            android:textStyle="bold"
            android:padding="8dp" />

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Thank You for Using Our Library"
            android:textSize="18sp"
            android:textStyle="bold"
            android:gravity="center"
            android:paddingTop="25dp" />

    </LinearLayout>
</ScrollView>


menu_main.xml:

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

<menu xmlns:android="http://schemas.android.com/apk/res/android">

    <item
        android:id="@+id/menu_home"
        android:title="Home" />

    <item
        android:id="@+id/menu_new"
        android:title="New Borrowing" />

    <item
        android:id="@+id/menu_exit"
        android:title="Exit" />

</menu>


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=".SummaryActivity"
            android:exported="false" />
        <activity
            android:name=".InvoiceActivity"
            android:exported="false" />
    </application>
</manifest>
