Supermarket Receipt
Write some code that could be used in a supermarket to calculate the total cost of items in a shopping cart and provide a receipt to the customer.
The supermarket has a catalog with different types of products (rice, apples, milk, toothbrushes,…). Each product has a price, and the total price of the shopping cart is the total of all the prices of the items. You get a receipt that details the items you’ve bought, the total price, and any discounts that were applied.
The supermarket runs special deals, e.g.
- Buy two toothbrushes, get one free. Normal toothbrush price is €0.99
- 20% discount on apples, normal price €1.99 per kilo.
- 10% discount on rice, normal price €2.49 per bag
- Five tubes of toothpaste for €7.49, normal price €1.79
- Two boxes of cherry tomatoes for €0.99, normal price €0.69 per box.
These are just examples: the actual special deals change each week.
Refactoring version
See also Supermarket Receipt Refactoring Kata
Acknowledgements
This exercise is loosely based on PragDave’s Kata01