From 9d2d11cb9d5041433d55a9b9425d3dce3d1aa5be Mon Sep 17 00:00:00 2001 From: alex Date: Tue, 14 Apr 2026 19:35:47 +0300 Subject: [PATCH 1/3] getReminder --- build.gradle.kts | 2 +- src/main/kotlin/mate/academy/NumberTransformation.kt | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 08780a4..cb2df04 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -20,7 +20,7 @@ tasks.test { } kotlin { - jvmToolchain(11) + jvmToolchain(17) } detekt { diff --git a/src/main/kotlin/mate/academy/NumberTransformation.kt b/src/main/kotlin/mate/academy/NumberTransformation.kt index 27818c6..20089f7 100644 --- a/src/main/kotlin/mate/academy/NumberTransformation.kt +++ b/src/main/kotlin/mate/academy/NumberTransformation.kt @@ -7,5 +7,8 @@ package mate.academy */ fun getReminder(numberStr: String?) : Int? { - return null + return numberStr?.toInt() + ?.times(3) + ?.plus(10) + ?.rem(11) } From 858988396b8e4d8f39d3d358e12880011875e428 Mon Sep 17 00:00:00 2001 From: alex Date: Tue, 14 Apr 2026 19:45:06 +0300 Subject: [PATCH 2/3] calculateTotalPrice --- src/main/kotlin/mate/academy/TotalPrice.kt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/mate/academy/TotalPrice.kt b/src/main/kotlin/mate/academy/TotalPrice.kt index d114745..2de7982 100644 --- a/src/main/kotlin/mate/academy/TotalPrice.kt +++ b/src/main/kotlin/mate/academy/TotalPrice.kt @@ -4,6 +4,7 @@ package mate.academy Calculate the products total price based on the provide price per product and products amount. If the price is not provided, use default price per product equal to 29.99 */ -fun calculateTotalPrice(pricePerProduct: Double?, count: Int) : Double { - return 0.0 +fun calculateTotalPrice(pricePerProduct: Double?, count: Int): Double { + val price = pricePerProduct ?: 29.99 + return price * count } From f2bef60a7add5affe05654768c045716b06af264 Mon Sep 17 00:00:00 2001 From: alex Date: Tue, 14 Apr 2026 19:55:56 +0300 Subject: [PATCH 3/3] constants --- src/main/kotlin/mate/academy/NumberTransformation.kt | 12 ++++++++---- src/main/kotlin/mate/academy/TotalPrice.kt | 4 +++- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/main/kotlin/mate/academy/NumberTransformation.kt b/src/main/kotlin/mate/academy/NumberTransformation.kt index 20089f7..d22e56e 100644 --- a/src/main/kotlin/mate/academy/NumberTransformation.kt +++ b/src/main/kotlin/mate/academy/NumberTransformation.kt @@ -6,9 +6,13 @@ package mate.academy If the number is not present return null */ -fun getReminder(numberStr: String?) : Int? { +private const val MULTIPLIER = 3 +private const val ADDITION_VALUE = 10 +private const val DIVISOR = 11 + +fun getReminder(numberStr: String?): Int? { return numberStr?.toInt() - ?.times(3) - ?.plus(10) - ?.rem(11) + ?.times(MULTIPLIER) + ?.plus(ADDITION_VALUE) + ?.rem(DIVISOR) } diff --git a/src/main/kotlin/mate/academy/TotalPrice.kt b/src/main/kotlin/mate/academy/TotalPrice.kt index 2de7982..5b7c1f9 100644 --- a/src/main/kotlin/mate/academy/TotalPrice.kt +++ b/src/main/kotlin/mate/academy/TotalPrice.kt @@ -1,10 +1,12 @@ package mate.academy +private const val DEFAULT_PRICE_PER_PRODUCT = 29.99 + /* Calculate the products total price based on the provide price per product and products amount. If the price is not provided, use default price per product equal to 29.99 */ fun calculateTotalPrice(pricePerProduct: Double?, count: Int): Double { - val price = pricePerProduct ?: 29.99 + val price = pricePerProduct ?: DEFAULT_PRICE_PER_PRODUCT return price * count }