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
112 changes: 112 additions & 0 deletions src/main/domain-model.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
# Bobs bagel

## Classdiagram
![img_1.png](img_1.png)

## Basket
| Classes | Members | Methods | Scenario | Output |
|---------|-----------------------------|---------------------------------|---------------------------------|----------------------------------------------------------------------|
| Basket | customerBasket: List\<Item> | | | |
| | capacity: int | | | |
| | | getAllItems() | at least one item | return all items |
| | | | empty | return nothing |
| | | getCap() | | return capacity |
| | | setCapacity(int newCap) | newCap > capacity | change capacity |
| | | | newCap <= capacity | do not change capacity |
| | | isFull() | basket is full | return true |
| | | | basket is not full | return false |
| | | getRemainingCapacity() | | return capacity - basket.size() |
| | | addItem(Item item, Inventory) | item is in inventory | add to basket |
| | | | item is not in inventory | do not add to basket |
| | | | basket is full | do not add to basket |
| | | removeItem(Item item) | item is in basket | remove from basket |
| | | | item is not in basket | do nothing |
| | | | basket is empty | do nothing |
| | | calculateTotalCost() | basket is empty | return 0 |
| | | | basket is not empty | calculate cost and return |
| | | applyDiscount() | basket has less than 5 items | no discount applied |
| | | | basket has > 5 and < 12 bagels | apply discount for 6 only |
| | | | basket has > 12 | apply discount for 12, and see if any further discount is applicable |
| | | | basket has one coffee and bagel | apply discount for bagel and coffee |

## User
| Classes | Members | Methods | Scenario | Output |
|---------|------------------|-------------------------------------------------|----------------------------------|------------------------------|
| User | name: String | | | |
| | DEFAULT_CAP: int | | | |
| | basket: Basket | | | |
| | | getName() | name given | return name |
| | | | no name given | returns no name |
| | | getBasket() | empty basket | no basket returned |
| | | | basket has at least one item | return basket with items |
| | | addItemToBasket(Item item, Inventory inventory) | item exists in inventory | add item to basket |
| | | | item does not exist in inventory | item is not added to basket |
| | | | basket is full | item is not added to basket |
| | | removeItemFromBasket(Item item) | item exists in basket | remove said item from basket |
| | | | item does not exist in basket | item is not removed |
| | | | basket is empty | nothing is done |


## Manager
### Does everything a User can do, but also has some extra accesses as shown below
| Classes | Member | Methods | Scenario | Output |
|---------|---------------------|------------------------------|------------------------------|------------------------------------------------|
| Manager | name: String | | | |
| | Inventory inventory | | | |
| | | changeCapacity(int capacity) | capacity > oldCapacity | change capacity to new capacity |
| | | | capacity <= oldCapacity | return message to show new capacity is too low |
| | | isInInventory(Item item) | fillings is in inventory | make bagel and serve customer |
| | | | fillings is not in inventory | tell customer that filling is not available |

## Customer
### Does everything a User can do, but also has some extra accesses as shown below
| Classes | Member | Methods | Scenario | Output |
|----------|----------------|--------------------------------------------------------|-----------------------------|------------------------------------------------|
| Customer | name:String | | | |
| | | totalCostOfBasket(Basket basket) | emptyBasket | show 0 |
| | | | at least one item in basket | calculate cost |
| | | showCostBeforeAdding(Items item (bagels and fillings)) | valid item | show cost |
| | | | not valid item | tell item is not valid |
| | | choseFillingsForBagel() | fillings in inventory | add fillings to basket |
| | | | fillings not in inventory | inform customer that fillings not in inventory |


## MemberPublic
### Does everything a User can do, has no extra accesses
| Classes | Member | Methods | Scenario | Output |
|--------------|----------------|-------------------------------------------------|----------------------------------|------------------------------|
| MemberPublic | name: String | | | |
| | basket: Basket | | | |
| | | addItemToBasket(Item item, Inventory inventory) | item exists in inventory | add item to basket |
| | | | item does not exist in inventory | item is not added to basket |
| | | | basket is full | item is not added to basket |
| | | removeItemFromBasket(Item item) | item exists in basket | remove said item from basket |
| | | | item does not exist in basket | item is not removed |
| | | | basket is empty | nothing is done |

## Items
| Classes | Member | Methods | Scenario | Output |
|---------|-----------------|--------------|-----------------------|----------------|
| Items | SKU: String | | | |
| | Price: float | | | |
| | name: String | | | |
| | Variant: String | | | |
| | | getSKU() | SKU available | return SKU |
| | | | SKU not available | return nothing |
| | | getPrice() | Price available | return price |
| | | | price not available | return nothing |
| | | getName() | name available | return name |
| | | | name not available | return nothing |
| | | getVariant() | variant available | return variant |
| | | | variant not available | return nothing |

## Inventory
| Classes | Member | Methods | Scenario | Output |
|-----------|------------------------|---------------------------|----------------------------------|------------------|
| Inventory | | | | |
| | inventory: List\<Item> | | | |
| | | isInInventory(String sku) | item exists in inventory | return true |
| | | | item does not exist in inventory | return false |
| | | getItem(String sku) | item is in inventory | return said item |
| | | | item is not in inventory | return null |

Binary file added src/main/img_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
41 changes: 41 additions & 0 deletions src/main/java/com/booleanuk/core/Bagel.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.booleanuk.core;

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

public class Bagel extends Item{

private List<Fillings> fillings = new ArrayList<>();

public Bagel(String SKU, double price, String name, String variant) {
super(SKU, price, name, variant);
}

public void addFillings(Fillings filling) {
fillings.add(filling);
}

public boolean removeFillings(Fillings filling, Inventory inventory) {
if(fillings.isEmpty() || !fillings.contains(filling) || !inventory.isInInventory(filling.getSKU())) {
return false;
}
else {
fillings.remove(filling);
return true;
}
}

public List<Fillings> getFillings() {
return fillings;
}

public double getBagelPrice() {
double totPrice = 0;
for (Fillings f: fillings) {
totPrice += f.getPrice();
}

totPrice += this.getPrice();
return totPrice;
}
}
109 changes: 109 additions & 0 deletions src/main/java/com/booleanuk/core/Basket.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
package com.booleanuk.core;

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

public class Basket {

private static int MAX_CAPACITY = 2;
private List<Item> customerBasket;

public Basket() {
this.customerBasket = new ArrayList<>();
}

public int getCapacity() {
return MAX_CAPACITY;
}

public void setCapacity(int newCapacity) {
this.MAX_CAPACITY = newCapacity;
}

public boolean isFull() {
return this.MAX_CAPACITY == customerBasket.size();
}

public int getRemainingCapacity() {
return MAX_CAPACITY - customerBasket.size();
}

public boolean addItem(Item item, Inventory inventory) {
if (isFull() || !inventory.isInInventory(item.SKU) || isFull()) {
return false;
}
else
customerBasket.add(item);

return true;
}

public boolean removeItem(Item item) {
if (customerBasket.isEmpty() || !customerBasket.contains(item)) {
return false;
}
else {
customerBasket.remove(item);
return true;
}
}

public double calculateDiscount() {
List<Item> bagels = new ArrayList<>();
int rest;
int quantDisc;

for (Item i: customerBasket) {
if (i.name.equals("Bagel")) {
bagels.add(i);
}
}

if (bagels.size() < 5) {
return calculateTotalCost();
}
else if (bagels.size() >= 6 && bagels.size() < 12) {
rest = bagels.size() % 6;
double totalCost = 2.49;

for (int i = bagels.size()-1; i > 5; i--) {
totalCost += bagels.get(i).getPrice();
}

return totalCost;
}
else {
quantDisc = bagels.size() / 12;
rest = bagels.size() % 12;
double totalCost = 0;

if (quantDisc >= 1) {
totalCost += quantDisc*3.99;
}

for (int i = bagels.size()-1; i > 11; i--) {
totalCost += bagels.get(i).getPrice();
}

return totalCost;
}
}

public double calculateTotalCost() {
double totalcost = 0;

for (Item i : customerBasket) {
totalcost += i.price;
}

return totalcost;
}

public boolean containsItem(Item item) {
return customerBasket.contains(item);
}

public void clearBasket() {
customerBasket.clear();
}
}
8 changes: 8 additions & 0 deletions src/main/java/com/booleanuk/core/Coffee.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.booleanuk.core;

public class Coffee extends Item {

public Coffee(String SKU, double price, String name, String variant) {
super(SKU, price, name, variant);
}
}
32 changes: 32 additions & 0 deletions src/main/java/com/booleanuk/core/Customer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.booleanuk.core;

import java.util.List;

public class Customer extends User{

public Customer(String name) {
super(name);
}

public String getName() {
return name;
}

public boolean addItemToBasket(Item item, Inventory inventory) {
return basket.addItem(item, inventory);
}

public boolean removeItemFromBasket(Item item) {
return basket.removeItem(item);
}

public double viewTotalCost() {
return basket.calculateTotalCost();
}

public double viewCostBeforeAdding(Item item) {
return item.getPrice();
}
}


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

public class Fillings extends Item{

public Fillings(String SKU, double price, String name, String variant) {
super(SKU, price, name, variant);
}
}
46 changes: 46 additions & 0 deletions src/main/java/com/booleanuk/core/Inventory.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package com.booleanuk.core;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;

import static java.lang.System.in;

public class Inventory {

private List<Item> inventory = new ArrayList<>(Arrays.asList(
new Bagel("BGLO", 0.49, "Bagel", "Onion" ),
new Bagel("BGLP", 0.39, "Bagel", "Plain"),
new Bagel("BGLE", 0.49, "Bagel", "Everything"),
new Bagel("BGLS", 0.49, "Bagel", "Sesame"),
new Coffee("COFB", 0.99, "Coffee", "Black"),
new Coffee("COFW", 1.19, "Coffee", "White"),
new Coffee("COFC", 1.29, "Coffee", "Cappuccino"),
new Coffee("COFL", 1.29, "Coffee", "Latte"),
new Fillings("FILB", 0.12, "Filling", "Bacon"),
new Fillings("FILE", 0.12, "Filling", "Egg"),
new Fillings("FILC", 0.12, "Filling", "Cheese"),
new Fillings("FILX", 0.12, "Filling", "Cream Cheese"),
new Fillings("FILS", 0.12, "Filling", "Smoked salmon"),
new Fillings("FILH", 0.12, "Filling", "Ham")
));

public boolean isInInventory(String sku) {
for (Item i: inventory) {
if (Objects.equals(i.SKU, sku)) {
return true;
}
}
return false;
}

public Item getItem(String sku) {
for (Item i: inventory) {
if (Objects.equals(i.SKU, sku)) {
return i;
}
}
return null;
}
}
32 changes: 32 additions & 0 deletions src/main/java/com/booleanuk/core/Item.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.booleanuk.core;

public class Item {

protected String SKU;
protected double price;
protected String name;
protected String variant;

public Item(String SKU, double price, String name, String variant) {
this.SKU = SKU;
this.price = price;
this.name = name;
this.variant = variant;
}

public String getVariant() {
return variant;
}

public String getName() {
return name;
}

public double getPrice() {
return price;
}

public String getSKU() {
return SKU;
}
}
Loading
Loading