We are building a shopping cart for an online grocery shop. The idea of this kata is to build the product in an iterative way.
Name | Cost | % Revenue | Price per unit | Tax | Final price |
Iceberg 🥬 | 1.55 € | 15 % | 1,79 € | Normal (21%) | 2.17 € |
Tomato 🍅 | 0.52 € | 15 % | 0.60 € | Normal (21%) | 0.73 € |
Chicken 🍗 | 1.34 € | 12 % | 1.51 € | Normal (21%) | 1.83 € |
Bread 🍞 | 0.71 € | 12 % | 0.80 € | First necessity (10%) | 0.88 € |
Corn 🌽 | 1.21 € | 12 % | 1.36 € | First necessity (10%) | 1.50 € |
Discounts code | Amount |
---|---|
PROMO_5 | 5% |
PROMO_10 | 10% |
As a customer
I want to see my shopping cart
--------------------------------------------
| Product name | Price with VAT | Quantity |
| ----------- | -------------- | -------- |
|------------------------------------------|
| Promotion: |
--------------------------------------------
| Total products: 0 |
| Total price: 0.00 € |
--------------------------------------------
As a customer
I want to add Iceberg 🥬 to my shopping cart
I want to add Tomato 🍅 to my shopping cart
I want to add Chicken 🍗 to my shopping cart
I want to add Bread 🍞 to my shopping cart
I want to add Corn 🌽 to my shopping cart
I want to see my shopping cart
--------------------------------------------
| Product name | Price with VAT | Quantity |
| ----------- | -------------- | -------- |
| Iceberg 🥬 | 2.17 € | 1 |
| Tomato 🍅 | 0.73 € | 1 |
| Chicken 🍗 | 1.83 € | 1 |
| Bread 🍞 | 0.88 € | 1 |
| Corn 🌽 | 1.50 € | 1 |
|------------------------------------------|
| Promotion: |
--------------------------------------------
| Total products: 5 |
| Total price: 7.11 € |
--------------------------------------------
As a customer
I want to add Iceberg 🥬 to my shopping cart
I want to add Iceberg 🥬 to my shopping cart
I want to add Iceberg 🥬 to my shopping cart
I want to add Tomato 🍅 to my shopping cart
I want to add Chicken 🍗 to my shopping cart
I want to add Bread 🍞 to my shopping cart
I want to add Bread 🍞 to my shopping cart
I want to add Corn 🌽 to my shopping cart
I want to see my shopping cart
--------------------------------------------
| Product name | Price with VAT | Quantity |
| ----------- | -------------- | -------- |
| Iceberg 🥬 | 2.17 € | 3 |
| Tomato 🍅 | 0.73 € | 1 |
| Chicken 🍗 | 1.83 € | 1 |
| Bread 🍞 | 0.88 € | 2 |
| Corn 🌽 | 1.50 € | 1 |
|------------------------------------------|
| Promotion: |
--------------------------------------------
| Total products: 8 |
| Total price: 12.33 € |
--------------------------------------------
As a customer
I want to add Iceberg 🥬 to my shopping cart
I want to add Iceberg 🥬 to my shopping cart
I want to add Iceberg 🥬 to my shopping cart
I want to add Tomato 🍅 to my shopping cart
I want to add Chicken 🍗 to my shopping cart
I want to add Bread 🍞 to my shopping cart
I want to add Bread 🍞 to my shopping cart
I want to add Corn 🌽 to my shopping cart
I want to apply my coupon code PROMO_5
I want to see my shopping cart
--------------------------------------------
| Product name | Price with VAT | Quantity |
| ----------- | -------------- | -------- |
| Iceberg 🥬 | 2.17 € | 3 |
| Tomato 🍅 | 0.73 € | 1 |
| Chicken 🍗 | 1.83 € | 1 |
| Bread 🍞 | 0.88 € | 2 |
| Corn 🌽 | 1.50 € | 1 |
|------------------------------------------|
| Promotion: 5% off with code PROMO_5 |
--------------------------------------------
| Total products: 8 |
| Total price: 11.71 € |
--------------------------------------------
You could change this API this is only for example purposes.
Approach 1 passing objects as arguments could be DTO
public interface ShoppingCart {
public void addItem(Product product);
public void deleteItem(Product product);
public void applyDiscount(Discount discount)
public void printShoppingCart();
}
public interface ShoppingCart {
public void addItem(String productName);
public void deleteItem(String productName);
public void applyDiscount(Double discount)
public void printShoppingCart();
}
Approach 3 passing primitives as arguments and returning a DTO
public interface ShoppingCart {
public void addItem(String productName);
public void deleteItem(String productName);
public void applyDiscount(Double discount)
public ShoppingCartList getShoppingCart();
}
The graphic examples that you can see in the assignment are not there to be implemented if you don't want to. They are provided as a reference of how the shopping cart works