Skip to content

Lab · Kotlin and Android App Development

Lab: a cloud kitchen's delivery day

Labbeginner· about 1.5 hours· 4 steps

The brief

QuickBite, a cloud kitchen in Pune, wants a quick report of its day. You model orders with a data class and an enum, show each order's status with a sealed type, price normal and express delivery with inheritance, and build the day report with collection operations.

Why it matters

Food delivery, e-commerce and banking apps are full of exactly these models: an order, a payment mode, a status that can only be one of a few things, and reports built with filter, groupBy and sumOf. The same sealed-class pattern drives loading, success and error screens in Android.

Skills you practise

  • data classes, equality and copy
  • enum classes with properties
  • sealed interfaces and exhaustive when
  • open classes and override
  • filter, sumOf, groupBy, maxByOrNull, groupingBy

You need

  • A web browser with the Kotlin Playground (play.kotlinlang.org), or IntelliJ IDEA / Android Studio with a Kotlin file that has fun main()

What you will have at the end

DeliveryDay.kt: order models with data, enum and sealed types, delivery pricing with inheritance, and a day report built with collection operations.

How it is marked (rubric, 100 points)
Right kind of classOrder is a data class, PayMode an enum, Status a sealed interface, Delivery an open class with an override.30
Correct reportSales of Rs 3089 without the cancelled order, the right totals by mode, the biggest order and the area counts.35
Collection operationsfilter, sumOf, groupBy, maxByOrNull and groupingBy instead of hand-written loops and counters.25
Readable codeClear names; when without else for the sealed type.10

0/4 steps done

Step 1 of 4

An order as a data class

Printing order 101 shows its fields, two orders with the same data are equal, and copy() makes a changed order.

A data class gets toString, equals and copy for free. toString prints every field, so logs are readable; equals compares the data, not the memory address; copy makes a new object with one field changed and leaves the original alone. The payment mode can only be UPI, card or cash, so it is an enum class with a label for each.

Make order 101, print it, compare it with == to a second Order built from the same values, and print a copy with amount = 400 (a Rs 50 coupon).

Run this on your machine, then paste the output below
$ Run DeliveryDay.kt in the Kotlin Playground and paste the output
Your notes: DeliveryDay.kt

Write down each command you ran. It goes into your project summary.