Lab · Kotlin and Android App Development
Lab: a chai stall's day in Kotlin
The brief
Sharma Chai Point sells cutting chai near a bus stand. You write one Kotlin program that adds up the day's cups, works out income and profit, names the day with when, prints a price board with a range, and labels a whole week with a loop.
Why it matters
Small calculations like these sit inside every billing, delivery and payments app: a total, a rule that picks a label, a loop over a list. Getting Int, Double and string templates right now saves hours of bugs later in Android code.
Skills you practise
- val and var
- Int and Double arithmetic
- string templates
- if expressions and when with ranges
- for loops, ranges, step and withIndex
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
ChaiStall.kt: a Kotlin program that prints the day's takings, a price board and a labelled week for a chai stall.
How it is marked (rubric, 100 points)
| Correct resultsEvery printed number matches: 225 cups, Rs 2700, Rs 2168.0 profit, the board and the week of 1550 cups. | 45 |
|---|---|
| Right types and keywordsval for things that never change, var only where needed, Double only for the milk. | 25 |
| Clear conditions and loopsOne when with ranges for the day label, a range with step for the board, withIndex for the week. | 20 |
| Readable codeClear names and string templates instead of joining strings with +. | 10 |
0/4 steps done
Step 1 of 4
Cups, income and profit
The program prints 225 cups sold, income Rs 2700, milk cost Rs 532.0 and profit Rs 2168.0.
The number of cups changes during the day, so it must be a var; the price never changes, so it is a val. Start cups at 0 and add each shift with +=. Income is cups times the price (an Int). Milk cost is 9.5 litres times Rs 56, and because 9.5 is a Double the result is a Double, so Kotlin prints 532.0. Profit is income minus milk cost, also a Double.
Print each line with a string template, for example println("Cups sold: $cups"). Run the program and paste everything it printed.
$ Run ChaiStall.kt in the Kotlin Playground and paste the outputAlso check yourself
Your notes: ChaiStall.kt
Write down each command you ran. It goes into your project summary.