Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions domain-model.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@


### Exercise

Follow the same process as above to translate these two user stories into domain models.

```
As a supermarket shopper,
So that I can pay for products at checkout,
I'd like to be able to know the total cost of items in my basket.
```

```
As an organised individual,
So that I can evaluate my shopping habits,
I'd like to see an itemised receipt that includes the name and price of the products
I bought as well as the quantity, and a total cost of my basket.
```

- Add your domain models to this repository as a file named `domain-model`. This should either be a `.md` file like this one, or a screenshot / picture of your work.
- Your model doesn't have to look like the example provided in this file. If you feel like you need more or less columns, feel free to go with that. There is no "right way" to do this kind of thing, we're just designing a system to make our lives easier when it comes to the coding part.

## Domain-model for shopping cart

| Classes | Variables | Methods | Scenario | Outcome |
|--------------|-------------------------------------------------|----------------------------------|-------------------------------------------------------------------|------------------------------------------------------------------------------------------|
| `CartManager` | `private HashMap<String, Integer> shoppingCart` | | | |
| | ` private int totalCost ` | | | |
| | `static HashMap<String, Integer> itemCostMap` | | | |
| | | `addItem(String item)` | Shopper adds an item to cart | Item is added to cart. If it exists, increment quantity counter. totalCost is updated. |
| | | `addItem(String item, int x)` | Add x items to cart | x items is added to cart. update totalCost |
| | | `removeItem(String item, int x)` | Shopper removes x items from cart | x items are removed from cart. update totalCost |
| | | `removeItem(String item)` | Shopper removes an item from the cart | If item is in cart, decrement the quantity counter. totalCost is updated. |
| | | `removeAllOfItem(String item)` | Shopper removes all quantities of item from cart | Item entry is removed from the cart map. totalCost is updated. |
| | | `getTotalCost()` | Shopper wants to know the total cost | Shopper gets the total cost of items in the cart. |
| | | `getQuantityOfItem(String item)` | Shopper wants to know the quantity of an item in the cart | Shopper gets the quantity of a given item from the cart. |
| | | `getItemizedReciept()` | Shopper wants to see an overview of all items in cart and total cost | Shopper gets the total cost of all items, and a list of how many items and the per-price |


21 changes: 21 additions & 0 deletions src/main/java/com/booleanuk/core/Basket.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.booleanuk.core;

import java.util.HashMap;

public class Basket {
public HashMap<String, Integer> items = new HashMap<>();

public boolean add(String product, int price){
boolean alreadyInBasket = items.containsKey(product);
items.put(product, price);
return alreadyInBasket;
}

public int total(){
int total = 0;
for(int price: items.values()){
total = total + price;
}
return total;
}
}
6 changes: 5 additions & 1 deletion src/main/java/com/booleanuk/core/CohortManager.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package com.booleanuk.core;

public class CohortManager {
import java.util.ArrayList;

public class CohortManager {
public boolean search(ArrayList<String> cohorts, String name){
return true;
}
}
40 changes: 40 additions & 0 deletions src/test/java/com/booleanuk/core/BasketTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.booleanuk.core;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

public class BasketTest {
public Basket getTestBasket(){
return new Basket();
}


@Test
public void testBasketConstructor(){
Basket basket = getTestBasket();
}

@Test
void testadd(){
Basket basket = getTestBasket();
basket.add("Banana", 10);
basket.add("Coca Cola", 20);
Assertions.assertTrue(basket.items.containsKey("Banana"));
Assertions.assertTrue(basket.items.containsKey("Coca Cola"));
Assertions.assertFalse(basket.items.containsKey("Unknown item"));
}

@Test
void testTotal(){
Basket basket = getTestBasket();
basket.add("Banana", 10);
basket.add("Coca Cola", 20);

Assertions.assertEquals(basket.total(), 30);

Assertions.assertNotEquals(basket.total(), 45); // should not be 45 yet
basket.add("kaptein sabeltann is", 15);
Assertions.assertEquals(basket.total(), 45); // should now be 45

}
}
3 changes: 2 additions & 1 deletion src/test/java/com/booleanuk/core/CohortManagerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

class CohortManagerTest {
import java.lang.reflect.Method;

class CohortManagerTest {
}