Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit beb8bb4

Browse files
committed
Initial code
1 parent 1eeb951 commit beb8bb4

File tree

4 files changed

+70
-0
lines changed

4 files changed

+70
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.serenitydojo.shoppingcart;
2+
3+
public class ShoppingCart {
4+
5+
public void add(int quantity, ShoppingItem item) {
6+
7+
}
8+
9+
public void calculateTotal() {
10+
11+
}
12+
13+
public void addSalesTax() {
14+
}
15+
16+
public void addBags(int numberOfBags) {
17+
}
18+
19+
public double getTotal() {
20+
return 0;
21+
}
22+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.serenitydojo.shoppingcart;
2+
3+
public class ShoppingItem {
4+
private final String name;
5+
private final String units;
6+
private final double price;
7+
private final String serialNumber;
8+
private final String brand;
9+
10+
public ShoppingItem(String name, String units, double price, String serialNumber, String brand) {
11+
12+
this.name = name;
13+
this.units = units;
14+
this.price = price;
15+
this.serialNumber = serialNumber;
16+
this.brand = brand;
17+
}
18+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package com.serenitydojo.shoppingcart;
2+
3+
import org.junit.Assert;
4+
import org.junit.Test;
5+
6+
public class WhenCalculatingTotalPrice {
7+
8+
@Test
9+
public void shouldCalculatePriceWhenArticlesAreAddedToTheCart() {
10+
ShoppingCart cart = new ShoppingCart();
11+
ShoppingItem item1 = new ShoppingItem("Rice", "1 kg", 4.99,"1235357214735835","Rice R Us");
12+
ShoppingItem item2 = new ShoppingItem("Milk", "1 lt", 3.99,"7879827234234232","Home Brand Dairy");
13+
ShoppingItem item3 = new ShoppingItem("Apples", "bag", 6.99,"345457584524562","Farmers Pick");
14+
ShoppingItem item4 = new ShoppingItem("Oranges", "bag", 7.99,"986865754876587","Farmers Pick");
15+
cart.add(2, item1);
16+
cart.add(3, item2);
17+
cart.add(1, item3);
18+
cart.add(1, item4);
19+
cart.calculateTotal();
20+
cart.addSalesTax();
21+
cart.addBags(3);
22+
double totalPrice = cart.getTotal();
23+
Assert.assertEquals(totalPrice, 100,0.0);
24+
}
25+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Coding with intent - refactoring code to make it express the WHAT as well as the HOW
2+
3+
In this exercise, we take a piece of existing code, try to understand it, and reorganise it into methods and objects so that it is easier to understand and easier to read. We will refactor both the test code _and_ the application code.
4+
5+
The domain is a shopping cart module, that finds the total cost of an order based on the number of articles and the shipping cost.

0 commit comments

Comments
 (0)