From 94a5d3b9db289ba74095434d326950accfceac57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=8C=E5=87=A2?= Date: Fri, 8 Mar 2019 11:28:35 +0800 Subject: [PATCH] Add koltin sample for website --- website/index/samples/sample.kotlin.txt | 28 +++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 website/index/samples/sample.kotlin.txt diff --git a/website/index/samples/sample.kotlin.txt b/website/index/samples/sample.kotlin.txt new file mode 100644 index 0000000000..ce0b94e41d --- /dev/null +++ b/website/index/samples/sample.kotlin.txt @@ -0,0 +1,28 @@ +const val POINTS_X_PASS: Int = 15 +val EZPassAccounts: MutableMap = mutableMapOf(1 to 100, 2 to 100, 3 to 100) +val EZPassReport: Map = EZPassAccounts + +// update points credit +fun updatePointsCredit(accountId: Int) { + if (EZPassAccounts.containsKey(accountId)) { + println("Updating $accountId...") + EZPassAccounts[accountId] = EZPassAccounts.getValue(accountId) + POINTS_X_PASS + } else { + println("Error: Trying to update a non-existing account (id: $accountId)") + } +} + +fun accountsReport() { + println("EZ-Pass report:") + EZPassReport.forEach{ + k, v -> println("ID $k: credit $v") + } +} + +fun main() { + accountsReport() + updatePointsCredit(1) + updatePointsCredit(1) + updatePointsCredit(5) + accountsReport() +} \ No newline at end of file