Skip to content
Closed
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
28 changes: 28 additions & 0 deletions BagelDomain.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@

| Classes | variables | Methods | Scenario | Outputs |
| ------------ | ----------------------------------------------------------- | ---------------------------------------------------------------------------- | ------------------------------------------------- | ---------------------------------------------------------------------- |
| Basket | Map<String bagelCode, entry<Bagel storeItem, int count>> orders | Basket() | create method | empty Basket |
| | int orderLimit | addOrder("String bagelName, int amount) | if bagelName is not correct or int amount is <= 0 | returns false |
| | | | if basket size is gone over | returns false |
| | | | if both valid and storeItem is not in basket yet | returns true, and the storeItem is added to the basket |
| | | | if both are valid and storeItem is already in basket | returns true, and the amount is added to the storeItem in basket |
| | | changeOrder(String bagelOrderToBeChanged, String new bagelOrder, int amount) | if all are valid | the storeItem version is changed and set to a new amount, true is returned |
| | | | | nothing happens and false is returned |
| | | removeOrder(String bagelName) | If name is in basket | the order is removed and true is returnd |
| | | | if not | returns false |
| | | changeSizeLimit(int newSizeLimit) | if >0 | returns true |
| | | | if < 0 | returns false |
| | | getTotalCost | empty or full | it calculated and returns the cost of all storeItems and fillings |
| | | | | |
| Bagel | String type | Bagel(String type) | if valid storeItem type | set as that storeItem |
| | | | if not | sets as default storeItem |
| | String filling | setBagelType(STring new type) | if valid storeItem | return true |
| | | | if not valid storeItem | returns false |
| | | setFillingType | if valid filiing | return true |
| | | | if not valid filling | return false |
| | | | | |
| StoreManager | Map<String bagelCodes, float price> priceListBagels | getBagelPrices() | | returns map of storeItem and prices |
| | Map<String fillingCodes, float price> priceListFilling | getFillingPrices() | | returns map of fillings and prices |
| | | getBagelPrice() | if valid | returns price |
| | | getFillingPrice() | if valid | returns price |
| | | | if not | returns -1 |
4 changes: 2 additions & 2 deletions EXTENSION1.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

In a normal supermarket, things are identified using Stock Keeping Units, or SKUs.

In Bob's Bagels, we'll use the first 3 letters of a bagel with an extra letter for the variant. For example: an 'everything bagel' has a SKU of `BGLE`.
In Bob's Bagels, we'll use the first 3 letters of a storeItem with an extra letter for the variant. For example: an 'everything storeItem' has a SKU of `BGLE`.

Our goods are priced individually. In addition, some items are multi-priced: buy n of them, and they'll cost you y pounds.

Expand All @@ -15,7 +15,7 @@ Our goods are priced individually. In addition, some items are multi-priced: buy
| BGLE | Bagel | Everything | .49 | 6 for 2.49 |
| COFB | Coffee | Black | .99 | Coffee & Bagel for 1.25 |

Every Bagel is available for the `6 for 2.49` and `12 for 3.99` offer, but fillings still cost the extra amount per bagel.
Every Bagel is available for the `6 for 2.49` and `12 for 3.99` offer, but fillings still cost the extra amount per storeItem.

#### Example orders
```
Expand Down
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Bob's Bagels - Object-oriented Programming

![](./assets/bagels.jpg)
![](./assets/storeItems.jpg)

## Learning Objectives
- Design a domain from user stories
Expand All @@ -26,21 +26,21 @@
```
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.
So I can order a storeItem before work,
I'd like to add a specific type of storeItem 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.
I'd like to remove a storeItem from my basket.
```

```
3.
As a member of the public,
So that I can not overfill my small bagel basket
So that I can not overfill my small storeItem basket
I'd like to know when my basket is full when I try adding an item beyond my basket capacity.
```

Expand Down Expand Up @@ -69,21 +69,21 @@ 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.
I'd like to know the cost of a storeItem 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.
I'd like to be able to choose fillings for my storeItem.
```

```
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.
I'd like to know the cost of each filling before I add it to my storeItem order.
```

```
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/com/booleanuk/core/BaconFilling.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.booleanuk.core;

public class BaconFilling extends Filling{
public BaconFilling() {
super ("Bacon Filling", "FILB");
}
}
90 changes: 90 additions & 0 deletions src/main/java/com/booleanuk/core/Basket.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package com.booleanuk.core;

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

public class Basket {

Map<String, Map.Entry<StoreItem, Integer>> orders;

public Basket() {
orders = new HashMap<>();
}

public Map<String, Map.Entry<StoreItem, Integer>> getOrders() {
return orders;
}

public boolean addOrder(String sku, int amount) {
int orderLimit = StoreManager.getBasketSize();

StoreItem storeItem = StoreItem.getBagelFromSKU(sku);
if (storeItem != null && amount > 0 && getOrderSize() + amount <= orderLimit) {
orders.merge(sku, Map.entry(storeItem, amount),
(a, b) -> Map.entry(storeItem, a.getValue()+b.getValue()));
return true;
}
return false;
}

public boolean changeOrder(String prevSKU, String newBagelSKU, int amount) {
int prevAmount = 0;
StoreItem newStoreItem = StoreItem.getBagelFromSKU(newBagelSKU);
if (orders.containsKey(prevSKU) && newStoreItem != null && amount > 0) {

if (prevSKU.equals(newBagelSKU)) {
return addOrder(newBagelSKU, amount);
} else {
if (addOrder(newBagelSKU, amount)){
orders.remove(prevSKU);
return true;
}
}
}
return false;
}

public boolean removeOrder(String bagelSKU) {
if (orders.containsKey(bagelSKU)) {
orders.remove(bagelSKU);
return true;
}
return false;
}



private int getOrderSize() {
int count =0;
for (var order : orders.entrySet()) {
count+= order.getValue().getValue();
}
return count;
}

public boolean setFilling(String bagelSKU, String fillingSKU) {
if (orders.containsKey(bagelSKU)) {
var set = orders.get(bagelSKU);
StoreItem storeItem = set.getKey();
if (storeItem.setFilling(fillingSKU)) {
orders.remove(bagelSKU);
orders.put(storeItem.getSKU() + fillingSKU, set);
return true;
}
}
return false;
}

public float getTotalCost() {
float cost =0;
for (var order : orders.entrySet()) {
var singleOrder = order.getValue();
StoreItem storeItem = singleOrder.getKey();
int amount = singleOrder.getValue();

cost += storeItem.getCost() * amount;
}
return cost;
}

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

public class CheeseFilling extends Filling{
public CheeseFilling() {
super("Cheese Filling", "FILC");
}
}
12 changes: 12 additions & 0 deletions src/main/java/com/booleanuk/core/CoffeeBlack.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.booleanuk.core;

public class CoffeeBlack extends StoreItem {
public CoffeeBlack() {
super("Coffee Black", "COFB", 0.99f);
}

@Override
public boolean setFilling(String filling) {
return false;
}
}
12 changes: 12 additions & 0 deletions src/main/java/com/booleanuk/core/CoffeeCapuccino.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.booleanuk.core;

public class CoffeeCapuccino extends StoreItem{
public CoffeeCapuccino() {
super("Coffee Cappuccino", "COFC", 1.29f);
}

@Override
public boolean setFilling(String filling) {
return false;
}
}
12 changes: 12 additions & 0 deletions src/main/java/com/booleanuk/core/CoffeeLatte.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.booleanuk.core;

public class CoffeeLatte extends StoreItem{
public CoffeeLatte() {
super("Coffee Latte", "COFL", 1.29f);
}

@Override
public boolean setFilling(String filling) {
return false;
}
}
12 changes: 12 additions & 0 deletions src/main/java/com/booleanuk/core/CoffeeWhite.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.booleanuk.core;

public class CoffeeWhite extends StoreItem{
public CoffeeWhite() {
super("Coffee White", "COFW", 1.19f);
}

@Override
public boolean setFilling(String filling) {
return false;
}
}
7 changes: 7 additions & 0 deletions src/main/java/com/booleanuk/core/CreamCheeseFilling.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.booleanuk.core;

public class CreamCheeseFilling extends Filling{
public CreamCheeseFilling() {
super("Cream Cheese Filling", "FILX");
}
}
7 changes: 7 additions & 0 deletions src/main/java/com/booleanuk/core/EggFilling.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.booleanuk.core;

public class EggFilling extends Filling{
public EggFilling() {
super("Egg Filling", "FILE");
}
}
8 changes: 8 additions & 0 deletions src/main/java/com/booleanuk/core/EverythingBagel.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.booleanuk.core;

public class EverythingBagel extends StoreItem {
public EverythingBagel() {
super("Everything Bagel","BGLE" , 0.49f);
}

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

import com.booleanuk.extension.ReceiptItem;

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

public abstract class Filling implements ReceiptItem {

private final String filling;
private final String sku;

public Filling(String filling, String sku) {
this.filling = filling;
this.sku = sku;
}

public String getName(){return filling;}

public float getCost() {
return 0.12f;}

public String getSKU() {
return sku;
}


public static Filling getFillingFromSKU(String sku) {
return switch (sku) {
case "FILB" -> new BaconFilling();
case "FILX" -> new CreamCheeseFilling();
case "FILE" -> new EggFilling();
case "FILC" -> new CheeseFilling();
case "FILS" -> new SmokedSalmonFilling();
case "FILH" -> new HamFilling();
default -> null;
};
}

public static Map<String, Float> getFillingPrices() {
Filling[] fillings = {new BaconFilling(), new CreamCheeseFilling(), new EggFilling(),
new CheeseFilling(), new SmokedSalmonFilling(), new HamFilling()};
Map<String, Float> priceList = new HashMap<>();
for (Filling filling: fillings) {
priceList.put(filling.getName(), filling.getCost());
}
return priceList;
}
}
9 changes: 9 additions & 0 deletions src/main/java/com/booleanuk/core/HamFilling.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.booleanuk.core;

public class HamFilling extends Filling {
public HamFilling() {
super("Ham Filling", "FILH");
}


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

public class OnionBagel extends StoreItem {
public OnionBagel() {
super("Onion Bagel", "BGLO", 0.49f);
}
}
10 changes: 10 additions & 0 deletions src/main/java/com/booleanuk/core/PlainBagel.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.booleanuk.core;

public class PlainBagel extends StoreItem {

public PlainBagel() {
super("Plain Bagel", "BGLP", 0.39f);
}


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

public class SesameBagel extends StoreItem {
public SesameBagel() {
super("Sesame Bagel", "BGLS", 0.49f);
}
}
7 changes: 7 additions & 0 deletions src/main/java/com/booleanuk/core/SmokedSalmonFilling.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.booleanuk.core;

public class SmokedSalmonFilling extends Filling{
public SmokedSalmonFilling() {
super("Smoked Salmon Filling", "FILS");
}
}
Loading
Loading