Skip to content

Lab · Kotlin and Android App Development

Lab: a tiffin service signup sheet

Labbeginner· about 1.5 hours· 4 steps

The brief

Annapurna Tiffin Service in Pune collects signups on paper, so some names and phone numbers are missing or messy. You print the list safely with null safety, write a bill function with default and named arguments, tidy the data with extension functions, and build an SMS list with lambdas and scope functions.

Why it matters

Every signup form, KYC screen and order form in an app gets empty boxes and messy input. Handling null without crashes, and cleaning phone numbers in one reusable place, is daily work for an Android developer.

Skills you practise

  • nullable types, ?. and ?:
  • let for nullable values
  • default and named arguments
  • extension functions
  • lambdas and higher-order functions
  • with and filter/map

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

TiffinSignup.kt: a Kotlin program that cleans a messy signup sheet safely and works out bills and offers.

How it is marked (rubric, 100 points)
Null safetyNo !! and no "null" in the output; ?. ?: and let are used where a value can be missing.30
Correct resultsBills of Rs 1820, 2120 and 3380, the offer of Rs 1638 and the right SMS list.35
Reusable functionsbill() with defaults, three String extensions and a higher-order applyOffer, each doing one job.25
Readable codeClear names; named arguments where a number could be confused.10

0/4 steps done

Step 1 of 4

Print the list without crashing on null

Each customer prints on one line, with "Guest" for the missing name and "missing" for the missing phone, and the program counts 1 missing phone.

names and phones are List<String?>: any item may be null. Kotlin will not let you call trim() on a String? directly, so use the safe call ?. (it gives null when the value is null) and the Elvis operator ?: to give a default. names[i]?.trim() ?: "Guest" trims a real name and gives Guest for null.

Loop over names.indices so you can read the same position in both lists. Number the lines from 1. Then count the phones that are null and print "Missing phones: 1".

Run this on your machine, then paste the output below
$ Run TiffinSignup.kt in the Kotlin Playground and paste the output

Also check yourself

Your notes: TiffinSignup.kt

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