Skip to content

Instantly share code, notes, and snippets.

@Raiden18
Last active May 16, 2022 11:05
Show Gist options
  • Save Raiden18/be5ce02d2fee31f33e8c2c9b47e9ab64 to your computer and use it in GitHub Desktop.
Save Raiden18/be5ce02d2fee31f33e8c2c9b47e9ab64 to your computer and use it in GitHub Desktop.
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