androidengineers.Book a session

Best Practices and Code Quality

Capstone: Advanced Kotlin Application

exercise90 minHard

Build a Kotlin study planner end to end

Create a Kotlin/JVM console application that accepts study sessions, stores them through a repository, and produces a deterministic report. The capstone combines the roadmap's concepts into one reviewable program.

Start with explicit domain types:

@JvmInline
value class TopicId(val value: String) {
    init { require(value.matches(Regex("[a-z0-9-]+"))) }
}

data class StudySession(val topic: TopicId, val minutes: Int) {
    init { require(minutes > 0) }
}

interface StudyRepository {
    suspend fun save(session: StudySession)
    suspend fun sessions(): List<StudySession>
}

Implement the vertical slice

First build an in-memory repository returning snapshots. Parse console input into explicit success/error outcomes before constructing a session. Add a pure report function grouping by topic and summing with Long, sorted by descending minutes and then identifier. Next add persistence behind the same interface, documenting file format, malformed-data behavior, and ownership of blocking I/O. Never silently overwrite unreadable data with an empty report.

Use structured coroutines where asynchronous operations are actually needed. Keep parsing and report calculation synchronous and pure. A DSL is optional; add one only if repeated plan configuration becomes clearer.

Acceptance checks

Demonstrate adding two Kotlin sessions and one Compose session, restarting with persisted data, and producing correct ordered totals. Test invalid IDs, nonpositive duration, malformed storage, save failure, cancellation, empty reports, and stable snapshots. A failed save must not produce a success confirmation.

Include a README with setup steps, the selected toolchain, example input/output, test commands, known limits, and design tradeoffs. Run static analysis and tests from a clean checkout.

Review question: which rules are enforced by types, which by runtime validation, and which only by tests? Your answer should cite concrete parts of your implementation.

Reference: Kotlin/JVM

YOUR LEARNING JOURNEY

0 of 110 available lessons completed

Progress saved in this browser. No account needed.
Capstone: Advanced Kotlin Application | Kotlin Core Programming | Android Engineers