Real World Example

Printing an Order Receipt

Apps like Swiggy and Zomato show a bill summary after checkout. Before building the UI, developers often write and test the text logic in plain Kotlin and print it to the console (or to Logcat on Android).

Example

A formatted receipt using println, tabs and templates:

fun main() {
    val restaurant = "Meghana Foods"
    // ---- Bill summary ----
    println("==============================")
    println("  $restaurant - Order #1042")
    println("==============================")
    println("Chicken Biryani x1\t₹ 320")
    println("Paneer 65       x1\t₹ 210")
    println("Delivery fee      \t₹ 30")
    println("------------------------------")
    println("To pay            \t₹ ${320 + 210 + 30}")
}

Output

==============================
  Meghana Foods - Order #1042
==============================
Chicken Biryani x1	₹ 320
Paneer 65       x1	₹ 210
Delivery fee      	₹ 30
------------------------------
To pay            	₹ 560

Logging on Android

On Android you do not use println for debugging; you use Log, which writes to Logcat with a tag and a level.

import android.util.Log

private const val TAG = "CheckoutScreen"

fun onPlaceOrder(orderId: Int) {
    Log.d(TAG, "Placing order $orderId")   // debug
    Log.e(TAG, "Payment failed")           // error
}

Exercise: Print this exactly, using one print and one println for the first line:
Order placed! Thank you.
Track it in the app.

Show answer
fun main() {
    print("Order placed! ")
    println("Thank you.")
    println("Track it in the app.")
}