Kotlinlearncs.online LogoJava
Return to List

Solve: Discount Calculator 2

Created By: Justin Maier
/ Version: 2024.7.0

An online shopping platform is having a sale and offering customers a discount depending on how much they spend. The discount levels are listed below. Customers are given the highest discount level that they qualify for (they never receive multiple discount levels).

  • Spend $300 or more: 20% off
  • Spend $150 or more: 10% off
  • Spend $75 or more: 5% off

There are two additional rules:

  • If a customer has a membership, the discount levels above are increased by 5%. For example, if a member spends $300 they would receive a 25% percent discount instead of a 20% discount. However, if a member does not qualify for any of the discount levels described above, they do not receive this additional 5% discount.
  • If a customer has a valid coupon code, they receive $15 off their purchase but only if their total is at least $50. This discount should be applied after applying the percentage discounts described above.

You are given a double variable subtotal that represents a customer's purchase total before applying the discount. You are also given boolean variables hasMembership and hasCouponCode. You should calculate the customer's final total after applying the discount and store it in double variable named finalTotal that you will need to declare. Fractional cents are okay; do not worry about restricting your answer to two decimal places.

Related Lessons

Stuck? You may find these lessons helpful: