Created
March 31, 2025 11:36
-
-
Save thimo/36e166962d6bd43c55dc0aa3df3c0d11 to your computer and use it in GitHub Desktop.
cart_calculator.rb
This file contains hidden or 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
class CartCalculator | |
def initialize(products) | |
@products = products | |
end | |
# Calculate the total price including: | |
# - Sum of all product prices | |
# - Apply bulk discount: 10% off when total exceeds $100 | |
# - Apply free shipping when total exceeds $50 (shipping cost is $10) | |
# Return a hash containing subtotal, discount, shipping, and final total | |
def calculate_total | |
# TODO: Implement this method | |
# | |
end | |
end | |
# Example product data structure: | |
# products = [ | |
# { name: "Book", price: 20 }, | |
# { name: "Pen", price: 5 } | |
# ] | |
# |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment