-
Notifications
You must be signed in to change notification settings - Fork 131
Marcus Ikdal #133
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
Open
Marcus0410
wants to merge
24
commits into
boolean-uk:main
Choose a base branch
from
Marcus0410:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Marcus Ikdal #133
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
37b818b
created all classes and models
Marcus0410 ba66602
small change
Marcus0410 361fbdb
changed type to be String
Marcus0410 a759948
added test for Item constructor
Marcus0410 6e51045
implemented Item getters
Marcus0410 274944f
tests for addItem
Marcus0410 4029046
added methods to basket and inventory
Marcus0410 fa7fcc8
removed ItemType and added tests for Inventory
Marcus0410 c58a247
implemented methods
Marcus0410 f8e6b27
fixed removeStock test
Marcus0410 177ab21
added test for removeItem()
Marcus0410 1ea2e40
added test for getTotalCost()
Marcus0410 c07b749
added all data from item data table
Marcus0410 a42e2c9
finished core
Marcus0410 af25001
created extension files
Marcus0410 ce0d5cb
added storied and domain model for receipt
Marcus0410 e05857b
added test for getReceipt()
Marcus0410 ea71b66
implemented Receipt
Marcus0410 43eef94
item is added back to stock when removed from basket
Marcus0410 a1b3923
added getItemCounts to Basket
Marcus0410 f469ebc
fixed receipt test
Marcus0410 0f17fdd
now shows total value for each item line on receipt
Marcus0410 62e8e7f
made Item abstract
Marcus0410 8dae7ac
implemented discounts
Marcus0410 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,4 +20,7 @@ gradle-app.setting | |
| # JDT-specific (Eclipse Java Development Tools) | ||
| .classpath | ||
|
|
||
| .idea | ||
| .idea | ||
|
|
||
| bin/ | ||
| .settings/ | ||
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| # Domain model | ||
|
|
||
| ## Item | ||
|
|
||
| | Method | Variable | Scenario | Output | | ||
| | ------------ | -------------- | -------- | ------------ | | ||
| | | SKU sku | | | | ||
| | | float price | | | | ||
| | | String type | | | | ||
| | | String variant | | | | ||
| | getSku() | | | return sku | | ||
| | getPrice() | | | return price | | ||
| | getType() | | | return type | | ||
| | getVariant() | | | return price | | ||
|
|
||
| ## Basket | ||
|
|
||
| | Method | Variable | Scenario | Output | | ||
| | ------------------- | ---------------------- | ------------------------------------------- | ----------------------------------- | | ||
| | | Inventory inventory | | | | ||
| | | int capacity | | | | ||
| | | ArrayList\<Item> items | | | | ||
| | addItem(Item item) | | basket is not full and item is in inventory | add item to items, return true | | ||
| | addItem(Item item) | | item is not in inventory | return false | | ||
| | addItem(Item item) | | basket is full | return false | | ||
| | removeItem(SKU sku) | | item exists in basket | remove item from items, return true | | ||
| | removeItem(SKU sku) | | item doesn't exist in basket | return false | | ||
| | getTotalCost() | | | return total cost of items | | ||
| | getItems() | | | return items | | ||
|
|
||
| ## Inventory | ||
|
|
||
| | Method | Variable | Scenario | Output | | ||
| | -------------------------------- | ---------------------------- | ----------------- | ----------------------------------- | | ||
| | | HashMap<SKU, Integer> invMap | | | | ||
| | checkStock(SKU sku) | | in stock | return true | | ||
| | checkStock(SKU sku) | | not in stock | return false | | ||
| | addStock(SKU sku, int amount) | | amount > 0 | add item to invMap, return true | | ||
| | addStock(SKU sku, int amount) | | amount <= 0 | return false | | ||
| | removeStock(SKU sku, int amount) | | item in stock | remove item from stock, return true | | ||
| | removeStock(SKU sku, int amount) | | item not in stock | return false | | ||
|
|
||
| ## Receipt | ||
|
|
||
| ### User stories | ||
|
|
||
| As a member of the public, | ||
| So I can assess the damage after paying, | ||
| I'd like to see the total cost of my order on the receipt. | ||
|
|
||
| As a member of the public, | ||
| So I can check if my order was handled correctly, | ||
| I'd like to see all items in my order listed on the receipt. | ||
|
|
||
| As a member of the public, | ||
| So I can double check the total cost, | ||
| I'd like to see the individual price of every item listed on the receipt. | ||
|
|
||
| As a member of the public, | ||
| So I can keep my finances in order, | ||
| I'd like to see the time of my purchase listed on the receipt. | ||
|
|
||
| | Method | Variable | Scenario | Output | | ||
| | -------------- | ---------------- | -------- | ------------------------- | | ||
| | | Basket basket | | | | ||
| | | String time | | | | ||
| | printReceipt() | | | print receipt to terminal | | ||
| | getReceipt() | | | return receipt String | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| package com.booleanuk.core; | ||
|
|
||
| public class Bagel extends Item { | ||
| public Bagel(SKU sku) { | ||
| super(sku); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| package com.booleanuk.core; | ||
|
|
||
| import java.util.ArrayList; | ||
|
|
||
| public class Basket { | ||
| private Inventory inventory; | ||
| private int capacity; | ||
| private ArrayList<Item> items = new ArrayList<>(); | ||
|
|
||
| public Basket(Inventory inventory, int capacity) { | ||
| this.inventory = inventory; | ||
| this.capacity = capacity; | ||
| } | ||
|
|
||
| boolean addItem(Item item) { | ||
| // if basket is not full and item is in stock | ||
| if (items.size() < capacity && inventory.checkStock(item.getSku())) { | ||
| items.add(item); | ||
| inventory.removeStock(item.getSku(), 1); // remove item from stock | ||
| return true; | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| boolean removeItem(SKU sku) { | ||
| for (int i = 0; i < items.size(); i++) { | ||
| if (items.get(i).getSku() == sku) { | ||
| items.remove(i); | ||
| inventory.addStock(sku, 1); | ||
| return true; | ||
| } | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| float getTotalCost() { | ||
| float total = 0f; | ||
| for (Item i : items) { | ||
| total += i.getPrice(); | ||
| } | ||
| return total; | ||
| } | ||
|
|
||
| ArrayList<Item> getItems() { | ||
| return items; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| package com.booleanuk.core; | ||
|
|
||
| public class Coffee extends Item { | ||
| public Coffee(SKU sku) { | ||
| super(sku); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| package com.booleanuk.core; | ||
|
|
||
| public class Filling extends Item { | ||
| public Filling(SKU sku) { | ||
| super(sku); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| package com.booleanuk.core; | ||
|
|
||
| import java.util.HashMap; | ||
|
|
||
| public class Inventory { | ||
| private HashMap<SKU, Integer> invMap = new HashMap<>(); | ||
|
|
||
| boolean checkStock(SKU sku) { | ||
| if (invMap.containsKey(sku) && invMap.get(sku) > 0) { | ||
| return true; | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| boolean addStock(SKU sku, int amount) { | ||
| if (amount <= 0) { | ||
| return false; | ||
| } | ||
| // if sku already in stock | ||
| if(invMap.containsKey(sku)) { | ||
| invMap.put(sku, invMap.get(sku) + amount); | ||
| } | ||
| // if sku not in stock | ||
| else { | ||
| invMap.put(sku, amount); | ||
| } | ||
| return true; | ||
| } | ||
|
|
||
| boolean removeStock(SKU sku, int amount) { | ||
| // if amount is more than in stock return false | ||
| if (!checkStock(sku) || amount > invMap.get(sku)) { | ||
| return false; | ||
| } | ||
|
|
||
| invMap.put(sku, invMap.get(sku) - amount); | ||
| return true; | ||
| } | ||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| package com.booleanuk.core; | ||
|
|
||
| public abstract class Item { | ||
| private SKU sku; | ||
| private float price; | ||
| private String type; | ||
| private String variant; | ||
|
|
||
| public Item(SKU sku) { | ||
| this.sku = sku; | ||
|
|
||
| // Set price, type, and variant based on SKU | ||
| if (sku == SKU.BGLO) { | ||
| price = 0.49f; | ||
| type = "Bagel"; | ||
| variant = "Onion"; | ||
| } else if (sku == SKU.BGLP) { | ||
| price = 0.39f; | ||
| type = "Bagel"; | ||
| variant = "Plain"; | ||
| } else if (sku == SKU.BGLE) { | ||
| price = 0.49f; | ||
| type = "Bagel"; | ||
| variant = "Everything"; | ||
| } else if (sku == SKU.BGLS) { | ||
| price = 0.49f; | ||
| type = "Bagel"; | ||
| variant = "Sesame"; | ||
| } else if (sku == SKU.COFB) { | ||
| price = 0.99f; | ||
| type = "Coffee"; | ||
| variant = "Black"; | ||
| } else if (sku == SKU.COFW) { | ||
| price = 1.19f; | ||
| type = "Coffee"; | ||
| variant = "White"; | ||
| } else if (sku == SKU.COFC) { | ||
| price = 1.29f; | ||
| type = "Coffee"; | ||
| variant = "Capuccino"; | ||
| } else if (sku == SKU.COFL) { | ||
| price = 1.29f; | ||
| type = "Coffee"; | ||
| variant = "Latte"; | ||
| } else if (sku == SKU.FILB) { | ||
| price = 0.12f; | ||
| type = "Filling"; | ||
| variant = "Bacon"; | ||
| } else if (sku == SKU.FILE) { | ||
| price = 0.12f; | ||
| type = "Filling"; | ||
| variant = "Egg"; | ||
| } else if (sku == SKU.FILC) { | ||
| price = 0.12f; | ||
| type = "Filling"; | ||
| variant = "Cheese"; | ||
| } else if (sku == SKU.FILX) { | ||
| price = 0.12f; | ||
| type = "Filling"; | ||
| variant = "Cream Cheese"; | ||
| } else if (sku == SKU.FILS) { | ||
| price = 0.12f; | ||
| type = "Filling"; | ||
| variant = "Smoked Salmon"; | ||
| } else if (sku == SKU.FILH) { | ||
| price = 0.12f; | ||
| type = "Filling"; | ||
| variant = "Ham"; | ||
| } else { | ||
| throw new IllegalArgumentException("Invalid SKU: " + sku); | ||
| } | ||
| } | ||
|
|
||
| SKU getSku() { | ||
| return sku; | ||
| } | ||
|
|
||
| float getPrice() { | ||
| return price; | ||
| } | ||
|
|
||
| String getType() { | ||
| return type; | ||
| } | ||
|
|
||
| String getVariant() { | ||
| return variant; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| package com.booleanuk.core; | ||
|
|
||
| public enum SKU { | ||
| BGLO, | ||
| BGLP, | ||
| BGLE, | ||
| BGLS, | ||
| COFB, | ||
| COFW, | ||
| COFC, | ||
| COFL, | ||
| FILB, | ||
| FILE, | ||
| FILC, | ||
| FILX, | ||
| FILS, | ||
| FILH, | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| package com.booleanuk.extension; | ||
|
|
||
| public class Bagel extends Item { | ||
| public Bagel(SKU sku) { | ||
| super(sku); | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will be difficult to maintain. Consider usg something like the factory pattern to refactor this