From 1d882f0ae17ed0d2d1127949415a363f811600fe Mon Sep 17 00:00:00 2001 From: allemangD Date: Thu, 11 Oct 2018 23:16:52 -0400 Subject: [PATCH] improve comments and readme --- README.md | 17 +++++++++++++++++ src/three_feature.kt | 4 +++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index b5033b6..22e8b35 100644 --- a/README.md +++ b/README.md @@ -10,3 +10,20 @@ Create a program (or programs) which show how the language you picked (Kotlin) w ## Report Card Generator +Accepts a file `sample.grades` where each line is an assignment in the format: `: `. The program iterates through the file and computes the average and letter grades for all courses listed in `sample.grades`. + +Language structures used include: + +* Iterable unpacking +* Implicit type arguments +* Null safety and propagation (as in `courses[course]!!.add(grade)`) +* Iteration +* Actions (as in `file.forEachLine`) +* Pattern matching (simple example using `when` expression) + +Kotlin library features used include: + +* File I/O +* Standard I/O +* String conversions +* Mutable maps and lists diff --git a/src/three_feature.kt b/src/three_feature.kt index d1b292d..c7d3022 100644 --- a/src/three_feature.kt +++ b/src/three_feature.kt @@ -16,8 +16,10 @@ fun main(args: Array) { // This is very brittle, though, if improperly formatted val (rawCourse, rawGrade) = it.split(":") + // use `trim()` to strip whitespace from either side of the strings + // string conversion is easy with helper methods like `toInt()` and `toIntOrNull()` val course = rawCourse.trim() - val grade = rawGrade.trim().toInt() // string conversion is easy with helper methods like `toInt()` and `toIntOrNull()` + val grade = rawGrade.trim().toInt() // collection testing is easy with `in` and `!in` operators if (course !in courses)