sample.kotlin.txt 815 B

12345678910111213141516171819202122232425262728
  1. const val POINTS_X_PASS: Int = 15
  2. val EZPassAccounts: MutableMap<Int, Int> = mutableMapOf(1 to 100, 2 to 100, 3 to 100)
  3. val EZPassReport: Map<Int, Int> = EZPassAccounts
  4. // update points credit
  5. fun updatePointsCredit(accountId: Int) {
  6. if (EZPassAccounts.containsKey(accountId)) {
  7. println("Updating $accountId...")
  8. EZPassAccounts[accountId] = EZPassAccounts.getValue(accountId) + POINTS_X_PASS
  9. } else {
  10. println("Error: Trying to update a non-existing account (id: $accountId)")
  11. }
  12. }
  13. fun accountsReport() {
  14. println("EZ-Pass report:")
  15. EZPassReport.forEach{
  16. k, v -> println("ID $k: credit $v")
  17. }
  18. }
  19. fun main() {
  20. accountsReport()
  21. updatePointsCredit(1)
  22. updatePointsCredit(1)
  23. updatePointsCredit(5)
  24. accountsReport()
  25. }