From eded7b38b54164a0fcba4bcf410d02b467212775 Mon Sep 17 00:00:00 2001 From: Duncan McGregor Date: Mon, 12 May 2025 09:38:18 +0100 Subject: [PATCH 1/2] Refactor GildedRose to use val instead of var for items, to better reflect the Java version. --- Kotlin/src/main/kotlin/com/gildedrose/GildedRose.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Kotlin/src/main/kotlin/com/gildedrose/GildedRose.kt b/Kotlin/src/main/kotlin/com/gildedrose/GildedRose.kt index 7ede7cee..33f752fd 100644 --- a/Kotlin/src/main/kotlin/com/gildedrose/GildedRose.kt +++ b/Kotlin/src/main/kotlin/com/gildedrose/GildedRose.kt @@ -1,6 +1,6 @@ package com.gildedrose -class GildedRose(var items: List) { +class GildedRose(val items: List) { fun updateQuality() { for (i in items.indices) { From 5358002d45ec96c70622bfcf97f431477033bddf Mon Sep 17 00:00:00 2001 From: Duncan McGregor Date: Mon, 12 May 2025 09:39:48 +0100 Subject: [PATCH 2/2] Reformat Item ctor and simplify toString --- Kotlin/src/main/kotlin/com/gildedrose/Item.kt | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Kotlin/src/main/kotlin/com/gildedrose/Item.kt b/Kotlin/src/main/kotlin/com/gildedrose/Item.kt index eaf62a40..cdf09407 100644 --- a/Kotlin/src/main/kotlin/com/gildedrose/Item.kt +++ b/Kotlin/src/main/kotlin/com/gildedrose/Item.kt @@ -1,7 +1,9 @@ package com.gildedrose -open class Item(var name: String, var sellIn: Int, var quality: Int) { - override fun toString(): String { - return this.name + ", " + this.sellIn + ", " + this.quality - } +open class Item( + var name: String, + var sellIn: Int, + var quality: Int, +) { + override fun toString(): String = "$name, $sellIn, $quality" } \ No newline at end of file