Project design
- Kotlin course
- Beginner
- Lesson 112/116
- 6 min
Design the skeleton of the beginner final mini app.
Project: Task tracker app
In this five-lesson beginner final you will build a task tracker app that combines everything you have learned. In the first lesson you define a Task class and print a task.
In later lessons you will add layers for adding tasks, completing them, error handling and putting the whole flow together. Each lesson adds one piece with a code step; the starting code includes the previous lesson's solution. This shows how a real app grows.
Task class design
A Task class carries a task's title (title) and completion state (done). The constructor sets the title; done defaults to false. toString shows the state in a readable form.
class Task(val title: String) {
var done: Boolean = false
override fun toString(): String {
return if (done) "[x] $title" else "[ ] $title"
}
}toString returns [x] title if done, otherwise [ ] title. When you print the list, each task's state is visible. This class is the foundation of the project.
Practice Define the Task class
Define the Task class: a val title: String constructor parameter, a var done: Boolean = false property and an override fun toString(): String method (prefix "[x] " if done, otherwise "[ ] " with title). In main create val t = Task("Study Kotlin") and print it with println.
Starter code
fun main() {
// Define a Task class; create an instance and print it
}Sample solution
class Task(val title: String) {
var done: Boolean = false
override fun toString(): String {
return if (done) "[x] $title" else "[ ] $title"
}
}
fun main() {
val t = Task("Study Kotlin")
println(t)
}Expected output
[ ] Kotlin çalış
Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 What will we manage in this project?
- Orders
- Customers
- Tasks Correct answer
- Invoices
Explanation: the project is a task tracker app; you add and complete tasks.
2 Fill in the blank: done property
class Task(val title: String) {
var ____: Boolean = false
}
class Task(val title: String) {
var done: Boolean = false
}
Explanation: var done: Boolean = false declares the completion state.
3 Match piece to role
| Term | Meaning |
|---|---|
title |
Task name |
done |
Is it done |
Task(title) |
Constructor |
var |
Mutable |