Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
a34b040
Add tests for Basket class
lucasholter00 Aug 7, 2025
2920d00
Add test for stock class
lucasholter00 Aug 7, 2025
e7465d5
Add missing @
lucasholter00 Aug 7, 2025
c957018
Implement Stock class.
lucasholter00 Aug 7, 2025
dabc17d
Add attributes as well as getters
lucasholter00 Aug 7, 2025
31de134
Add getter for specific items to stock
lucasholter00 Aug 7, 2025
c093917
Add null test for invalid code when searching for item in stock
lucasholter00 Aug 7, 2025
c8d4989
Fix method call on null object
lucasholter00 Aug 7, 2025
65597d7
Update tests, add new tests for child classes to item
lucasholter00 Aug 8, 2025
da13c02
Complete bagel test and add implementation
lucasholter00 Aug 8, 2025
376b7e2
Finishes
lucasholter00 Aug 8, 2025
ef7bd0e
Last commit
lucasholter00 Aug 8, 2025
e98d03b
Add files into extension, and test case for basket for extension
lucasholter00 Aug 8, 2025
9110fd5
Add domain model
lucasholter00 Aug 11, 2025
b1be6a4
Implement discounted price and add extra test
lucasholter00 Aug 11, 2025
877414e
Create test class for reciept, add domain model for reciept
lucasholter00 Aug 11, 2025
9bc9838
Change expected results on basket to include coffee discount
lucasholter00 Aug 11, 2025
7cfd9ec
Change implementation to include discount
lucasholter00 Aug 11, 2025
8e18ed6
Expand domain model and add comment to basket
lucasholter00 Aug 11, 2025
153fc00
Expand domain model
lucasholter00 Aug 11, 2025
8e8b7de
Test reciept object directly instead of through basket
lucasholter00 Aug 11, 2025
abec22e
Add tests for Reciept class
lucasholter00 Aug 11, 2025
59cdccd
Change tests to reflect new method
lucasholter00 Aug 11, 2025
5ff591b
Add reciept functionallity
lucasholter00 Aug 11, 2025
bd5539d
Add changes to domain model
lucasholter00 Aug 11, 2025
6119be8
Expand domain model and add test for discounted reciept
lucasholter00 Aug 12, 2025
26c9c5a
Add implementation and fix bug with discount
lucasholter00 Aug 12, 2025
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_diagram.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
131 changes: 131 additions & 0 deletions domain-model.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
| Module | Class | Member | Method | Scenario | Output |
|--------|------------------|--------------------|-------------------------------|------------------------------|------------|
| Core | Basket | List<Item> items | add(String sku) | Correct code basket not full | 1 |
| | | int capacity | | Correct code basket full | 0 |
| | | static stdCapacity | | Incorrect code | -1 |
| | | static Stock stock | remove(String sku) | Exists | True |
| | | | | Doesn't exist | False |
| | | | getTotalCost() | | float |
| | Stock | List<Item> stock | | | |
| | | | getPrice(String sku) | Exists | price |
| | | | | Doesn't exist | -1 |
| | | | getFillings() | | List<Item> |
| | | | getItem(String sku) | Exists | Item |
| | | | | Does not exist | null |
| | Abstract Item | String sku | getSku() | | sku |
| | | float price | getPrice() | | price |
| | | String name | getName() | | name |
| | | String variant | getVariant() | | variant |
| | | | | | |
| | Bagel | List<Filling> | addFilling(Filling filling) | | void |
| | | | removeFilling(String variant) | Filling exists in list | true |
| | Coffee | | | Filling does not exist | false |
| | Filling | | | | |
| | | | | | |
Extension 1:
As a user I want to take part of the special offers so that I can save money.

| Module | Class | Member | Method | Scenario | Output |
|--------|---------------|--------------------|-------------------------------|------------------------------|---------------|
| Core | Basket | List<Item> items | add(String sku) | Correct code basket not full | 1 |
| | | int capacity | | Correct code basket full | 0 |
| | | static stdCapacity | | Incorrect code | -1 |
| | | static Stock stock | remove(String sku) | Exists | True |
| | | | | Doesn't exist | False |
| | | | getTotalCost() | | float |
| | | | getDiscountetCost() | | |
| | Stock | List<Item> stock | | | |
| | | | getPrice(String sku) | Exists | price |
| | | | | Doesn't exist | -1 |
| | | | getFillings() | | List<Item> |
| | | | getItem(String sku) | Exists | Item |
| | | | | Does not exist | null |
| | Abstract Item | String sku | getSku() | | sku |
| | | float price | getPrice() | | price |
| | | String name | getName() | | name |
| | | String variant | getVariant() | | variant |
| | | | | | |
| | Bagel | List<Filling> | addFilling(Filling filling) | | void |
| | | | removeFilling(String variant) | Filling exists in list | true |
| | | | | Filling does not exist | false |
| | | | getFillings() | | List<Filling> |
| | Coffee | | | | |
| | Filling | | | | |
| | | | | | |

Extension 2:
As a user I want to get a reciept with my order so that I can know what I have bought.

| Module | Class | Member | Method | Scenario | Output |
|--------|---------------|--------------------|-------------------------------|------------------------------|-----------------|
| Core | Basket | List<Item> items | add(String sku) | Correct code basket not full | 1 |
| | | int capacity | | Correct code basket full | 0 |
| | | static stdCapacity | | Incorrect code | -1 |
| | | static Stock stock | remove(String sku) | Exists | True |
| | | | | Doesn't exist | False |
| | | | getTotalCost() | | float |
| | | | getDiscountetCost() | | |
| | | | getPriceInfo() | | List<PriceInfo> |
| | Stock | List<Item> stock | | | |
| | | | getPrice(String sku) | Exists | price |
| | | | | Doesn't exist | -1 |
| | | | getFillings() | | List<Item> |
| | | | getItem(String sku) | Exists | Item |
| | | | | Does not exist | null |
| | Abstract Item | String sku | getSku() | | sku |
| | | float price | getPrice() | | price |
| | | String name | getName() | | name |
| | | String variant | getVariant() | | variant |
| | | | | | |
| | Bagel | List<Filling> | addFilling(Filling filling) | | void |
| | | | removeFilling(String variant) | Filling exists in list | true |
| | | | | Filling does not exist | false |
| | | | getFillings() | | List<Filling> |
| | Coffee | | | | |
| | Filling | | | | |
| | | | | | |
| | Reciept | Basket basket | getReciept() | | String |
| | | | | | |
| | PriceInfo | String name | | | |
| | | float cost | | | |
| | | float discount | | | |
| | | int count | | | |

Extension 3:
As a user I want to get a reciept with my order and discounts so that I can know what I have bought andhow much I have saved.

| Module | Class | Member | Method | Scenario | Output |
|--------|---------------|--------------------|-------------------------------|------------------------------|-----------------|
| Core | Basket | List<Item> items | add(String sku) | Correct code basket not full | 1 |
| | | int capacity | | Correct code basket full | 0 |
| | | static stdCapacity | | Incorrect code | -1 |
| | | static Stock stock | remove(String sku) | Exists | True |
| | | | | Doesn't exist | False |
| | | | getTotalCost() | | float |
| | | | getDiscountetCost() | | |
| | | | getPriceInfo() | | List<PriceInfo> |
| | Stock | List<Item> stock | | | |
| | | | getPrice(String sku) | Exists | price |
| | | | | Doesn't exist | -1 |
| | | | getFillings() | | List<Item> |
| | | | getItem(String sku) | Exists | Item |
| | | | | Does not exist | null |
| | Abstract Item | String sku | getSku() | | sku |
| | | float price | getPrice() | | price |
| | | String name | getName() | | name |
| | | String variant | getVariant() | | variant |
| | | | | | |
| | Bagel | List<Filling> | addFilling(Filling filling) | | void |
| | | | removeFilling(String variant) | Filling exists in list | true |
| | | | | Filling does not exist | false |
| | | | getFillings() | | List<Filling> |
| | Coffee | | | | |
| | Filling | | | | |
| | | | | | |
| | Reciept | Basket basket | getReciept() | | String |
| | | | getDiscountedReciept() | | String |
| | PriceInfo | String name | | | |
| | | float cost | | | |
| | | float discount | | | |
| | | int count | | | |

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

import java.util.ArrayList;
import java.util.List;

public class Bagel extends Item{
List<Filling> fillings;

public Bagel(String sku, float price, String variant){
super(sku, price, "Bagel", variant);
this.fillings = new ArrayList<>();
}

public void addFilling(Filling filling){
this.fillings.add(filling);
}

public boolean removeFilling(String variant){
for(int i = 0; i < this.fillings.size(); i++){
if(this.fillings.get(i).getVariant().equals(variant)){
this.fillings.remove(i);
return true;
}
}
return false;
}

public List<Filling> getFillings(){
return this.fillings;
}

@Override
public float getPrice(){
float acc = 0;
for(Filling filling : this.fillings){
acc += filling.getPrice();
}
return super.getPrice() + acc;
}
}
58 changes: 58 additions & 0 deletions src/main/java/com/booleanuk/core/Basket.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package com.booleanuk.core;

import java.util.ArrayList;
import java.util.List;

public class Basket {
private List<Item> items;
private int capacity;
static private int stdCapacity = 3;
static private Stock stock = new Stock();

public Basket(){
this.capacity = stdCapacity;
items = new ArrayList<>();
}

public Basket(int capacity){
this.capacity = capacity;
items = new ArrayList<>();
}

public List<Item> getItems(){
return this.items;
}

public int add(String sku) {
if(items.size() >= capacity){
return 0;
}

Item addItem = stock.getItem(sku);

if(addItem == null){
return -1;
}

items.add(addItem);
return 1;
}

public boolean remove(String sku){
for(int i = 0; i < this.items.size(); i++){
if(this.items.get(i).getSku().equals(sku)){
this.items.remove(i);
return true;
}
}
return false;
}

public float getTotalCost(){
float acc = 0.0f;
for(Item curr : this.items){
acc = acc + curr.getPrice();
}
return acc;
}
}
7 changes: 7 additions & 0 deletions src/main/java/com/booleanuk/core/Coffee.java
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(String sku, float price, String variant){
super(sku, price, "Coffee", variant);
}
}
10 changes: 10 additions & 0 deletions src/main/java/com/booleanuk/core/Filling.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.booleanuk.core;

import java.util.ArrayList;

public class Filling extends Item{
public Filling(String sku, float price, String variant){
super(sku, price, "Filling", variant);
}

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

public abstract class Item {
private String sku;
private float price;
private String name;
private String variant;

public Item(String sku, float price, String name, String variant){
this.sku = sku;
this.price = price;
this.name = name;
this.variant = variant;
}

public String getSku(){
return this.sku;
}

public float getPrice(){
return this.price;
}

public String getName(){
return this.name;
}

public String getVariant(){
return this.variant;
}
}
Loading
Loading