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 androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {

    EditText etName, etMobile;
    RadioGroup rgMeal;
    RadioButton rbVeg, rbNonVeg;
    CheckBox cbPizza, cbBurger, cbSandwich, cbSoftDrink;
    Button btnPlaceOrder;

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

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

        rgMeal = findViewById(R.id.rgMeal);
        rbVeg = findViewById(R.id.rbVeg);
        rbNonVeg = findViewById(R.id.rbNonVeg);

        cbPizza = findViewById(R.id.cbPizza);
        cbBurger = findViewById(R.id.cbBurger);
        cbSandwich = findViewById(R.id.cbSandwich);
        cbSoftDrink = findViewById(R.id.cbSoftDrink);
        btnPlaceOrder = findViewById(R.id.btnPlaceOrder);
        btnPlaceOrder.setOnClickListener(v -> {
            String name = etName.getText().toString().trim();

            String mobile = etMobile.getText().toString().trim();

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

            if (!mobile.matches("[0-9]{10}")) {
                etMobile.setError("Enter exactly 10 digits");
                etMobile.requestFocus();
                return;
            }

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

            String meal;

            if (rbVeg.isChecked()) {
                meal = "Vegetarian";
            } else {
                meal = "Non-Vegetarian";
            }

            if (!cbPizza.isChecked()
                    && !cbBurger.isChecked()
                    && !cbSandwich.isChecked()
                    && !cbSoftDrink.isChecked()) {

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

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

            intent.putExtra("name", name);
            intent.putExtra("mobile", mobile);
            intent.putExtra("meal", meal);


            intent.putExtra("pizza", cbPizza.isChecked());
            intent.putExtra("burger", cbBurger.isChecked());
            intent.putExtra("sandwich", cbSandwich.isChecked());
            intent.putExtra("drink", cbSoftDrink.isChecked());

            startActivity(intent);
        });
    }
}


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="FOOD ORDER"
            android:textSize="26sp"
            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="Customer Name"
            android:inputType="textPersonName" />

        <EditText
            android:id="@+id/etMobile"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"

            android:layout_marginTop="10dp"
            android:hint="Mobile Number"
            android:inputType="phone"
            android:maxLength="10" />

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

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

            <RadioButton
                android:id="@+id/rbVeg"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Vegetarian" />

            <RadioButton
                android:id="@+id/rbNonVeg"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Non-Vegetarian" />

        </RadioGroup>

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

        <CheckBox
            android:id="@+id/cbPizza"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Pizza - ₹250" />



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

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

        <CheckBox
            android:id="@+id/cbSoftDrink"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Soft Drink - ₹60" />

        <Button
            android:id="@+id/btnPlaceOrder"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="25dp"
            android:text="PLACE ORDER" />
    </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, tvMobile, tvMeal, tvItems, tvBill;
    Button btnInvoice;

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

        tvName = findViewById(R.id.tvName);
        tvMobile = findViewById(R.id.tvMobile);
        tvMeal = findViewById(R.id.tvMeal);
        tvItems = findViewById(R.id.tvItems);
        tvBill = findViewById(R.id.tvBill);
        btnInvoice = findViewById(R.id.btnInvoice);

        Intent intent = getIntent();

        String name = intent.getStringExtra("name");
        String mobile = intent.getStringExtra("mobile");
        String meal = intent.getStringExtra("meal");

        boolean pizza = intent.getBooleanExtra("pizza", false);
        boolean burger = intent.getBooleanExtra("burger", false);
        boolean sandwich = intent.getBooleanExtra("sandwich", false);
        boolean drink = intent.getBooleanExtra("drink", false);

        StringBuilder items = new StringBuilder();
        double bill = 0;

        if (pizza) {
            items.append("Pizza, ");
            bill += 250;
        }

        if (burger) {
            items.append("Burger, ");
            bill += 150;
        }

        if (sandwich) {
            items.append("Sandwich, ");
            bill += 120;
        }

        if (drink) {
            items.append("Soft Drink, ");
            bill += 60;
        }

        if (items.length() > 2) {
            items.delete(items.length() - 2, items.length());
        }



        final double totalBill = bill;

        tvName.setText("Customer Name : " + name);
        tvMobile.setText("Mobile Number : " + mobile);
        tvMeal.setText("Meal Type : " + meal);
        tvItems.setText("Food Items : " + items);
        tvBill.setText("Total Bill : ₹" + totalBill);

        btnInvoice.setOnClickListener(v -> {

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

            invoiceIntent.putExtra("name", name);
            invoiceIntent.putExtra("mobile", mobile);
            invoiceIntent.putExtra("meal", meal);
            invoiceIntent.putExtra("items", items.toString());
            invoiceIntent.putExtra("bill", totalBill);

            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="ORDER 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/tvMobile"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textSize="18sp"
            android:padding="8dp" />

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

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

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

        <Button
            android:id="@+id/btnInvoice"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="25dp"
            android:text="GENERATE INVOICE" />


    </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, tvMobile, tvMeal, tvItems, tvBill, tvDiscount, tvFinal;

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

        tvName = findViewById(R.id.tvName);
        tvMobile = findViewById(R.id.tvMobile);
        tvMeal = findViewById(R.id.tvMeal);
        tvItems = findViewById(R.id.tvItems);
        tvBill = findViewById(R.id.tvBill);
        tvDiscount = findViewById(R.id.tvDiscount);
        tvFinal = findViewById(R.id.tvFinal);
        Intent intent = getIntent();
        String name = intent.getStringExtra("name");
        String mobile = intent.getStringExtra("mobile");
        String meal = intent.getStringExtra("meal");
        String items = intent.getStringExtra("items");
        double bill = intent.getDoubleExtra("bill", 0);
        double discount = 0;
        if (bill >= 500) {
            discount = bill * 0.15;
        } else if (bill >= 300) {
            discount = bill * 0.10;
        }
        double finalAmount = bill - discount;
        tvName.setText("Customer Name : " + name);
        tvMobile.setText("Mobile Number : " + mobile);
        tvMeal.setText("Meal Type : " + meal);
        tvItems.setText("Food Items : " + items);

        tvBill.setText("Total Bill : ₹" + bill);
        tvDiscount.setText("Discount : ₹" + discount);
        tvFinal.setText("Final Amount Payable : ₹" + 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="FINAL INVOICE"
            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/tvMobile"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textSize="18sp"
            android:padding="8dp" />

        <TextView
            android:id="@+id/tvMeal"

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

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

        <TextView
            android:id="@+id/tvBill"
            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 Visiting Our Restaurant"
            android:textSize="18sp"
            android:textStyle="bold"
            android:gravity="center"
            android:paddingTop="25dp" />
    </LinearLayout>
</ScrollView>


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>
