Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jan Rusak #31

Open
wants to merge 42 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
bcb9ddb
Added domain-model.md
DorotaWlazlo Jul 12, 2023
cafa91a
Add class-model-core.png
JRusak Jul 12, 2023
c2cf762
Added classes skeletons
DorotaWlazlo Jul 12, 2023
ace231c
Added tests for core requirements
DorotaWlazlo Jul 13, 2023
dd68a5d
Add products to Inventory
JRusak Jul 13, 2023
9c0696e
Merge remote-tracking branch 'origin/main'
JRusak Jul 13, 2023
ad1110b
Added add and remove methods
DorotaWlazlo Jul 13, 2023
b11889b
Merge remote-tracking branch 'origin/main'
JRusak Jul 13, 2023
98192e4
Remove gitkeeps
JRusak Jul 13, 2023
d3c4dd6
Added changeCostOfProducts and totalCost
DorotaWlazlo Jul 13, 2023
b055bc8
Implement checkCostOfProduct(String productVariant) method
JRusak Jul 13, 2023
eaee8b8
Merge remote-tracking branch 'origin/main'
JRusak Jul 13, 2023
1a5aeb2
Updated checkCostOfProducts() test
JRusak Jul 13, 2023
9748e91
Update tests for Core.
JRusak Jul 13, 2023
72d393f
Added outline of extension classes
DorotaWlazlo Jul 13, 2023
c2e7752
Change keys in products map in Inventory to SKUs
JRusak Jul 13, 2023
faa38f7
Merge remote-tracking branch 'origin/main'
JRusak Jul 13, 2023
fa76bc8
Update ExtensionInventory
JRusak Jul 13, 2023
1e55c9e
Rename files and add domain-model-extension.md
JRusak Jul 13, 2023
1a7ade3
First version of discount counting
DorotaWlazlo Jul 13, 2023
2b098a5
Change price type from double to int and implemented working discount…
JRusak Jul 13, 2023
ae55373
Extension #1 done
JRusak Jul 13, 2023
30e6a42
Update domain-model-extension.md
JRusak Jul 13, 2023
7ffccaf
Changes made in discounts and starting receipts.
DorotaWlazlo Jul 13, 2023
d0b1a93
Update BasketTest in Extension
JRusak Jul 16, 2023
14cee26
Add BargainTest
JRusak Jul 16, 2023
2bdaf45
Add Bargain
JRusak Jul 16, 2023
c51a813
Add CombinationBargainTest
JRusak Jul 16, 2023
745d995
Add CombinationBargain
JRusak Jul 16, 2023
e920de5
Add ProductTest
JRusak Jul 16, 2023
9385499
Update Product in Extension
JRusak Jul 16, 2023
ee0d28f
Add InventoryTest in Extension
JRusak Jul 16, 2023
8a51f1c
Update Inventory in Extension
JRusak Jul 16, 2023
50492cd
Update Basket in Extension
JRusak Jul 16, 2023
99f511d
Add CheckoutTest in Extension
JRusak Jul 16, 2023
fbb381e
Add Checkout in Extension
JRusak Jul 16, 2023
a1d8b21
Add ReceiptTest in Extension
JRusak Jul 16, 2023
a9f3a62
Add Receipt in Extension
JRusak Jul 16, 2023
0afa129
Add ReceiptGeneratorTest in Extension
JRusak Jul 16, 2023
8a7e52e
Add ReceiptGenerator in Extension
JRusak Jul 16, 2023
19f38d8
Update domain-model-extension.md
JRusak Jul 16, 2023
3a20c1c
Add class-model-extension.png
JRusak Jul 16, 2023
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
Binary file added class-model-core.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added class-model-extension.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
90 changes: 90 additions & 0 deletions domain-model-core.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
# Bob's bagels
### Dorota Wlazło, Jan Rusak

```
1.
As a member of the public,
So I can order a bagel before work,
I'd like to add a specific type of bagel to my basket.
```
```
2.
As a member of the public,
So I can change my order,
I'd like to remove a bagel from my basket.
```
```
3.
As a member of the public,
So that I can not overfill my small bagel basket
I'd like to know when my basket is full when I try adding an item beyond my basket capacity.
```
```
4.
As a Bob's Bagels manager,
So that I can expand my business,
I’d like to change the capacity of baskets.
```
```
5.
As a member of the public
So that I can maintain my sanity
I'd like to know if I try to remove an item that doesn't exist in my basket.
```
```
6.
As a customer,
So I know how much money I need,
I'd like to know the total cost of items in my basket.
```
```
7.
As a customer,
So I know what the damage will be,
I'd like to know the cost of a bagel before I add it to my basket.
```
```
8.
As a customer,
So I can shake things up a bit,
I'd like to be able to choose fillings for my bagel.
```
```
9.
As a customer,
So I don't over-spend,
I'd like to know the cost of each filling before I add it to my bagel order.
```
```
10.
As the manager,
So we don't get any weird requests,
I want customers to only be able to order things that we stock in our inventory.
```

| Class | Field | Method | Condition | Output |
|--------|----------------------------------------|---------------------------------------------------|-----------------------------------------------------------------------------------------------|----------------------------------|
| Basket | Hashmap<String, Integer> productsCount | boolean add(String productVariant, int amount) | if there are less products in total than capacity | true |
| | | | if there are more products in total than capacity or the productVariant is N/A or amount <= 0 | false |
| | int capacity | | | |
| | int currentAmountOfProducts | boolean remove(String productVariant, int amount) | if the amount of products of sku in basket is >= amount | true |
| | | | if the amount of products of sku in basket is < amount or amount <= 0 | false |
| | | boolean changeCapacity(int newCapacity) | if newCapacity >= currentAmount | true |
| | | | if newCapacity < currentAmount | false |
| | | double totalCost() | always | total cost of products in basket |
| | | double checkCostOfProduct(String productVariant) | always | cost of product by sku |

| Class | Field | Method | Condition | Output |
|---------|----------------|--------|-----------|--------|
| Product | String sku | | | |
| | double price | | | |
| | String name | | | |
| | String variant | | | |


| Class | Field | Method | Condition | Output |
|-----------|-----------------------------------|-------------------------------------------|-----------------------------------|-----------------|
| Inventory | Hashmap<String, Product> products | Product getProduct(String productVariant) | if product exist in the inventory | Product product |
| | | | if product doesn't exists | null |


70 changes: 70 additions & 0 deletions domain-model-extension.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
| Class | Field | Method | Condition | Output |
|---------|--------------|-------------------|-----------|---------|
| Bargain | int packSize | bargain6Bagels() | | Bargain |
| | int packCost | bargain12Bagels() | | Bargain |


| Class | Field | Method | Condition | Output |
|--------|----------------------------------------|-----------------------------------------------|-------------------------------------------------------------------------------------------|--------|
| Basket | Hashmap<String, Integer> productsCount | boolean add(String productSKU, int amount) | if there are less products in total than capacity | true |
| | int capacity | | if there are more products in total than capacity or the productSKU is N/A or amount <= 0 | false |
| | int currentAmountOfProducts | boolean remove(String productSKU, int amount) | if the amount of products of sku in basket is >= amount | true |
| | | | if the amount of products of sku in basket is < amount or amount <= 0 | false |
| | | boolean changeCapacity(int newCapacity) | if newCapacity >= currentAmount | true |
| | | | if newCapacity < currentAmount | false |
| | | void clearBasket() | | void |


| Class | Field | Method | Condition | Output |
|----------|------------------------------------|--------------------------------------------------------------|-----------|-------------------------------------|
| Checkout | HashMap<String, Integer> costs | static int getProductsCost(String productSKU, int quantity) | | products cost without discounts |
| | HashMap<String, Integer> amounts | static double countBasketCostWithoutDiscounts(Basket basket) | | basket total cost without discounts |
| | HashMap<String, Integer> discounts | static double countBasketCostWithDiscounts(Basket basket) | | basket total cost with discounts |
| | double totalCost | Receipt getReceipt() | | receipt object |
| | double totalDiscount | | | |
| | Basket basket | | | |


| Class | Field | Method | Condition | Output |
|--------------------|---------------------------|---------------------------------------------------|-----------|--------------------------|
| CombinationBargain | String name | static List<CombinationBargain> coffeePlusBagel() | | List<CombinationBargain> |
| | List<String> productsSKUs | | | |
| | int price | | | |


| Class | Field | Method | Condition | Output |
|-----------|-----------------------------------------------------|---------------------------------------------------------|-----------------------------|-----------------------------------|
| Inventory | static Hashmap<String, Product> products | static List<Bargain> getBargains(String productSKU) | if product not on any sale | empty List<Bargain> |
| | static List<CombinationBargain> combinationBargains | | if product on sale | List<Bargain> |
| | static HashMap<String, List<Bargain>> bargains | static boolean productNotInInventory(String productSKU) | if product not in inventory | true |
| | | | if product in inventory | false |
| | | static int checkCostOfTheProduct(String productSKU) | if product in inventory | product price |
| | | | if product not in inventory | 0 |
| | | static Product getProduct(String productSKU) | if product in inventory | Product |
| | | | if product not in inventory | null |
| | | static String getProductDescription(String productSKU) | if product in inventory | variant + name, np. "Onion Bagel" |
| | | | if product not in inventory | productSKU |


| Class | Field | Method | Condition | Output |
|---------|----------------|--------|-----------|--------|
| Product | String sku | | | |
| | double price | | | |
| | String name | | | |
| | String variant | | | |


| Class | Field | Method | Condition | Output |
|---------|------------------------------------|---------------------------------------|----------------------------------|----------|
| Receipt | HashMap<String, Integer> costs | double getDiscount(String productSKU) | if product discount in discounts | discount |
| | HashMap<String, Integer> amounts | | if no discount for product | 0 |
| | HashMap<String, Integer> discounts | double getCost(String productSKU) | if product cost in costs | cost |
| | double totalCost | | if product cost not in costs | 0 |
| | double totalDiscount | int getQuantity(String productSKU) | if product amount in amounts | quantity |
| | LocalDateTime creationDate | | if product amount not in amounts | 0 |


| Class | Field | Method | Condition | Output |
|------------------|-------|-----------------------------------------|-----------|-------------------|
| ReceiptGenerator | | String generateReceipt(Receipt receipt) | | formatted receipt |
| | | | | |
Empty file.
69 changes: 69 additions & 0 deletions src/main/java/com/booleanuk/core/Basket.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package com.booleanuk.core;

import java.util.HashMap;

public class Basket {
private final HashMap<String, Integer> productsCount;
private int capacity;
private int currentAmountOfProducts;

public Basket(int capacity) {
productsCount = new HashMap<>();
this.capacity = capacity;
currentAmountOfProducts = 0;
}

public boolean add(String productSKu, int amount){
if (amount <= 0 || amount + currentAmountOfProducts > capacity || !Inventory.getProducts().containsKey(productSKu))
return false;

if (productsCount.containsKey(productSKu))
productsCount.put(productSKu, productsCount.get(productSKu) + amount);
else
productsCount.put(productSKu, amount);

currentAmountOfProducts += amount;
return true;
}

public boolean remove(String productSKu, int amount){
if (amount <= 0 || !productsCount.containsKey(productSKu) || productsCount.get(productSKu) < amount)
return false;

productsCount.put(productSKu, productsCount.get(productSKu) - amount);

if (productsCount.get(productSKu) == 0)
productsCount.remove(productSKu);

currentAmountOfProducts -= amount;
return true;
}

public boolean changeCapacity(int newCapacity){
if (newCapacity < currentAmountOfProducts || newCapacity == 0)
return false;

capacity = newCapacity;
return true;
}

public double totalCost(){
double cost = 0;
for (String productSKu : productsCount.keySet()) {
cost += productsCount.get(productSKu) * Inventory.getProducts()
.get(productSKu)
.getPrice();
}
return cost;
}

public double checkCostOfProduct(String productSKu){
var products = Inventory.getProducts();

if (!products.containsKey(productSKu))
return 0.0d;

return products.get(productSKu)
.getPrice();
}
}
28 changes: 28 additions & 0 deletions src/main/java/com/booleanuk/core/Inventory.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.booleanuk.core;

import java.util.HashMap;

public class Inventory {
private static final HashMap<String, Product> products = new HashMap<>() {{
put("BGLO", new Product("BGLO", 0.49d, "Bagle", "Onion"));
put("BGLP", new Product("BGLP", 0.39d, "Bagle", "Plain"));
put("BGLE", new Product("BGLE", 0.49d, "Bagle", "Everything"));
put("BGLS", new Product("BGLS", 0.49d, "Bagle", "Sesame"));

put("COFB", new Product("COFB", 0.99d, "Coffee", "Black"));
put("COFW", new Product("COFW", 1.19d, "Coffee", "White"));
put("COFC", new Product("COFC", 1.29d, "Coffee", "Capuccino"));
put("COFL", new Product("COFL", 1.29d, "Coffee", "Latte"));

put("FILB", new Product("FILB", 0.12d, "Filling", "Bacon"));
put("FILE", new Product("FILE", 0.12d, "Filling", "Egg"));
put("FILC", new Product("FILC", 0.12d, "Filling", "Cheese"));
put("FILX", new Product("FILX", 0.12d, "Filling", "Cream Cheese"));
put("FILS", new Product("FILS", 0.12d, "Filling", "Smoked Salmon"));
put("FILH", new Product("FILH", 0.12d, "Filling", "Ham"));
}};

public static HashMap<String, Product> getProducts() {
return products;
}
}
31 changes: 31 additions & 0 deletions src/main/java/com/booleanuk/core/Product.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.booleanuk.core;

public class Product {
private String sku;
private double price;
private String name;
private String variant;

public Product(String sku, double price, String name, String variant) {
this.sku = sku;
this.price = price;
this.name = name;
this.variant = variant;
}

public String getSku() {
return sku;
}

public double getPrice() {
return price;
}

public String getName() {
return name;
}

public String getVariant() {
return variant;
}
}
Empty file.
12 changes: 12 additions & 0 deletions src/main/java/com/booleanuk/extension/Bargain.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.booleanuk.extension;

public record Bargain(int packSize, int packCost) {

public static Bargain bargain6Bagels() {
return new Bargain(6, 249);
}

public static Bargain bargain12Bagels() {
return new Bargain(12, 399);
}
}
62 changes: 62 additions & 0 deletions src/main/java/com/booleanuk/extension/Basket.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package com.booleanuk.extension;

import java.util.HashMap;

public class Basket {

private final HashMap<String, Integer> productsCount;
private int capacity;
private int currentAmountOfProducts;

public Basket(int capacity) {
productsCount = new HashMap<>();
this.capacity = capacity;
currentAmountOfProducts = 0;
}

public boolean add(String productSKU, int amount){
if (amount <= 0 || amount + currentAmountOfProducts > capacity || Inventory.productNotInInventory(productSKU))
return false;
if (productsCount.containsKey(productSKU))
productsCount.put(productSKU, productsCount.get(productSKU) + amount);
else
productsCount.put(productSKU, amount);
currentAmountOfProducts += amount;
return true;
}

public boolean remove(String productSKU, int amount){
if (amount <= 0 || !productsCount.containsKey(productSKU) || productsCount.get(productSKU) < amount)
return false;
productsCount.put(productSKU, productsCount.get(productSKU) - amount);
if (productsCount.get(productSKU) == 0)
productsCount.remove(productSKU);
currentAmountOfProducts -= amount;
return true;
}

public boolean changeCapacity(int newCapacity){
if (newCapacity < currentAmountOfProducts || newCapacity == 0)
return false;
capacity = newCapacity;
return true;
}

public HashMap<String, Integer> getProductsCount() {
return productsCount;
}

public int getCapacity() {
return capacity;
}

public int getCurrentAmountOfProducts() {
return currentAmountOfProducts;
}

public void clearBasket() {
productsCount.clear();
currentAmountOfProducts = 0;
}
}

Loading