Last active
May 16, 2022 11:05
-
-
Save Raiden18/be5ce02d2fee31f33e8c2c9b47e9ab64 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data class Product( | |
val title: String, | |
val price: BigDecimal, | |
val discount: BigDecimal // Value from 0.00% to 1.00% | |
) | |
data class Wishlist( | |
val products: List<Product> | |
){ | |
fun getAllProductsPrice(): BigDecimal { | |
return products.sumOf { | |
val priceWithoutDiscount = it.price | |
val discount = priceWithoutDiscount * it.discount // Should be part of the Product class | |
priceWithoutDiscount - discount // Should be part of the Product class | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment