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
1 change: 1 addition & 0 deletions EXERCISE1.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,6 @@ I'd like to see an itemised receipt that includes the name and price of the prod
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.
59 changes: 59 additions & 0 deletions domain-model.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Domain model

<!-- TOC -->
* [Domain model](#domain-model)
* [User stories](#user-stories)
* [User story 1](#user-story-1)
* [User story 2](#user-story-2)
* [Classes](#classes)
* [Product Class](#product-class)
* [Shopping Basket Class](#shopping-basket-class)
<!-- TOC -->

## User stories
### User story 1
```
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.
```

### User story 2
```
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.
```

## Classes

### Product Class
| Variables | Description |
|--------------------|----------------------------|
| String productID | ID of the product |
| String productName | Name of the product |
| String description | Description of the product |
| Float price | Price of the product |


### Shopping Basket Class
| Variables | Description |
|----------------------------------------------|----------------------------------------------------------------------|
| List<Product product, Integer quantity> basket | Contains all the products in the user's basket |
| String customerID | Contains the ID of the customer |
| Boolean paymentCompleted | Is true if the payment of the basket is completed. False by default. |


| Methods | Scenario | Outputs |
|------------------------------------------------------|----------------------------------------------------|-------------------------|
| `Void addItem(Product product, Integer quantity)` | Customer adds product(s) to basket | - |
| `Void removeItem(Product product, Integer quantity)` | Customer removes product(s) from basket | - |
| `Float summarizeBasket(Basket basket)` | If basket is empty | Return 0 |
| | If basket is not empty | Return sum |
| `Void completePayment(Basket basket)` | If basket is empty | Return error |
| | If basket is not empty and payment is successful | - |
| | If basket is not empty and payment is unsuccessful | Return error |
| `String createReceipt(Basket basket)` | If basket.paymentCompleted == true | Return itemised receipt |
| | If basket.paymentCompleted == false | Return error |

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

import java.util.HashMap;
import java.util.Map;

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

public boolean add(String product, int price){

if (items.containsKey(product))
return false;

items.put(product, price);
return true;
}

public int total(){
int sum = 0;

for (Map.Entry<String, Integer> item : items.entrySet()) {
sum += item.getValue();
}
return sum;
}

}
1 change: 1 addition & 0 deletions src/main/java/com/booleanuk/core/CohortManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
public class CohortManager {

}

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

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

public class BasketTest {

@Test
public void testAdd() {
Basket basket = new Basket();
basket.add("Banana", 5);
Assertions.assertFalse(basket.add("Banana", 5));
Assertions.assertTrue(basket.add("Pear", 3));
}

@Test
public void testTotal() {
Basket basket = new Basket();
basket.add("Banana", 5);
basket.add("Apple", 4);
basket.add("Pear", 3);
Assertions.assertEquals(12, basket.total());
}
}
1 change: 1 addition & 0 deletions src/test/java/com/booleanuk/core/CohortManagerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@

class CohortManagerTest {


}