Skip to content
AgileLogics
Beginner 5 min read

Beginner Projects

Prerequisites: Level 1 — Beginner

Build these with nothing but what Level 1 covered — println, readln, variables, null safety, if and when, loops, collections, functions, and lambdas. Each one fits in a single .kt file with a main function.

1. Command-Line Calculator

Read two numbers and an operator (+ - * /) with readln(), convert them with toDoubleOrNull(), and compute the result with a when expression. Print a clear message for invalid numbers, an unknown operator, or division by zero.

Hint: toDoubleOrNull() returns null for bad input — combine it with the Elvis operator ?: to handle it.

2. Number Guessing Game

Pick a secret number with (1..100).random(), then loop, reading guesses and printing "Too high" or "Too low" until the player gets it right. Count and print the attempts.

3. To-Do List

Keep tasks in a mutableListOf<Pair<String, Boolean>>() (title and done flag). Loop over a menu (add / list / done / quit) handled with when, and use forEachIndexed to print numbered tasks with a [x] or [ ] marker.

4. Unit Converter

Store conversion factors in a map (mapOf("km→mi" to 0.621371, ...)), list the options, and convert the number the user enters. Format results with "%.2f".format(value).

5. Password Generator

Ask for a length, then build a password from a pool of letters, digits, and symbols with (1..length).map { pool.random() }.joinToString(""). Refuse lengths under 8.

6. Simple Quiz

Store questions and answers in a list of pairs, ask each one, compare answers ignoring case with equals(answer, ignoreCase = true), and print a final score like You scored 4/5.

7. Word Frequency Counter

Read a sentence, split it into lowercase words, count them with groupingBy { it }.eachCount(), and print the five most common words.