diff --git a/src/classDiagramBeforeExtension.png b/src/classDiagramBeforeExtension.png new file mode 100644 index 000000000..2a97f0348 Binary files /dev/null and b/src/classDiagramBeforeExtension.png differ diff --git a/src/classDiagramWithExtension.png b/src/classDiagramWithExtension.png new file mode 100644 index 000000000..1614322df Binary files /dev/null and b/src/classDiagramWithExtension.png differ diff --git a/src/domain-model.md b/src/domain-model.md new file mode 100644 index 000000000..2b41f0bf4 --- /dev/null +++ b/src/domain-model.md @@ -0,0 +1,89 @@ +# Bob's bagels + +## Menu +| Method | Member variable | Scenario | Result | +|-----------------------------------|-----------------------------|-------------------------------------------|--------------------------| +| | ArrayList itemsOnMenu | | | +| seePrice(Item anItem) | | The item exist in the inventory | String show price | +| | | The item dont exist in the inventory | String error message | +| | | | | +| showAllFillingsWithCosts() | | List all fillings in that are on the menu | String with all fillings | +| | | | | +| | | | | +| isContainedInInventory(Item item) | | item is contained in the inventory | True | +| | | item is not contained in the inventory | False | + + +## Basket +| Method | Member variable | Scenario | Result | +|---------------------------------|-------------------------------|-----------------------------------|---------------------------------------------| +| addItem(Item anItem) | ArrayList itemsInBasket | basket is full | String Error message | +| | int size | basket is not full | String success message | +| | | | | +| removeItem(Item anItem) | | item is not contained in basket | String Error message | +| | | item is contained in basket | String success message | +| | | | | +| changeSizeOfBasket(int newSize) | | entering acceptable size | True | +| | | entering non-acceptable size | False | +| | | | | +| totalCost() | | basket consists of atleast 1 item | Double total cost of basket | +| | | basket dont consist any items | 0 | +| | | | | +| //EXTENSION | | | | +| totalCostWithDiscounts() | | discounts are received | Double total cost of basket minus discounts | +| | | discounts are not received | Double total cost of basket | + + +## Items +| Method | Member Variable | Scenario | Result | +|---------------------|---------------------|----------|--------| +| | Double price | | | +| | String abbreviation | | | +| | String name | | | +| | String typeOfItem | | | +| getters and setters | | | | + + +## Coffee +| Method | Member Variable | Scenario | Result | +|---------------------|---------------------|----------|--------| +| | Float price | | | +| | String abbreviation | | | +| | String name | | | +| getters and setters | | | | + + +## Bagel +| Method | Member Variable | Scenario | Result | +|---------------------|---------------------|----------|--------| +| | Float price | | | +| | String abbreviation | | | +| | String name | | | +| getters and setters | | | | + + +## Filling +| Method | Member Variable | Scenario | Result | +|---------------------|---------------------|----------|--------| +| | Float price | | | +| | String abbreviation | | | +| | String name | | | +| getters and setters | | | | + + + +// EXTENSION +## Receipt + +| Method | Member Variable | Scenario | Result | +|----------------------------------------------|----------------------------------------------|-----------------------------------|---------------------------------------------| +| | HashMap itemsThatArePurchased | | | +| | String dateOfPurchase | | | +| printReceipt() | | basket consists of atleast 1 item | String receipt returned and is also printed | +| | | basket dont contain any items | String Error message | +| | | | | +| totalCostWithDiscounts() | | discounts are received | Double total cost of basket minus discounts | +| | | discounts are not received | Double total cost of basket | +| | | | | +| costWithDiscounts(Item anItem, int quantity) | | discounts are received | Double cost of item minus discounts | +| | | discounts are not received | Double cost of item | diff --git a/src/main/java/com/booleanuk/core/BaconFilling.java b/src/main/java/com/booleanuk/core/BaconFilling.java new file mode 100644 index 000000000..23b76064f --- /dev/null +++ b/src/main/java/com/booleanuk/core/BaconFilling.java @@ -0,0 +1,7 @@ +package com.booleanuk.core; + +public class BaconFilling extends Filling{ + public BaconFilling(Double price, String abbreviation, String name, String typeOfItem){ + super(price, abbreviation, name, typeOfItem); + } +} diff --git a/src/main/java/com/booleanuk/core/Bagel.java b/src/main/java/com/booleanuk/core/Bagel.java new file mode 100644 index 000000000..ef5f99a91 --- /dev/null +++ b/src/main/java/com/booleanuk/core/Bagel.java @@ -0,0 +1,7 @@ +package com.booleanuk.core; + +public class Bagel extends Item{ + public Bagel(Double price, String abbreviation, String name, String typeOfItem){ + super(price, abbreviation, name, typeOfItem); + } +} diff --git a/src/main/java/com/booleanuk/core/Basket.java b/src/main/java/com/booleanuk/core/Basket.java new file mode 100644 index 000000000..80c9f0435 --- /dev/null +++ b/src/main/java/com/booleanuk/core/Basket.java @@ -0,0 +1,56 @@ +package com.booleanuk.core; + +import java.util.ArrayList; + +public class Basket { + private ArrayList itemsInBasket; + private int size; + + public Basket(ArrayList itemsInBasket, int size){ + this.itemsInBasket = itemsInBasket; + this.size = size; + } + + public void setItemsInBasket(ArrayList itemsInBasket) { + this.itemsInBasket = itemsInBasket; + } + + public void setSize(int size) { + this.size = size; + } + + public String addItem(Item itemToAdd){ + if(this.itemsInBasket.size() < this.size){ + this.itemsInBasket.add(itemToAdd); + return itemToAdd.getName() + " was added to your basket!"; + } + return "Basket is full!"; + } + + public String removeItem(Item itemToRemove){ + for(Item item : itemsInBasket){ + if(item.getName().equals(itemToRemove.getName())){ + itemsInBasket.remove(item); + return itemToRemove.getName() + " was removed from the basket!"; + } + } + return "Item do not exist in basket!"; + } + + public boolean changeSizeOfBasket(int newSize){ + if(newSize > 0 && newSize >= this.itemsInBasket.size()){ + setSize(newSize); + return true; + } + return false; + } + + public double totalCost(){ + double totalCost = 0; + for(Item item : this.itemsInBasket){ + totalCost += item.getPrice(); + } + return totalCost; + } + +} diff --git a/src/main/java/com/booleanuk/core/BlackCoffee.java b/src/main/java/com/booleanuk/core/BlackCoffee.java new file mode 100644 index 000000000..e1a316c2e --- /dev/null +++ b/src/main/java/com/booleanuk/core/BlackCoffee.java @@ -0,0 +1,7 @@ +package com.booleanuk.core; + +public class BlackCoffee extends Coffee{ + public BlackCoffee(Double price, String abbreviation, String name, String typeOfItem){ + super(price, abbreviation, name, typeOfItem); + } +} diff --git a/src/main/java/com/booleanuk/core/CappucinoCoffee.java b/src/main/java/com/booleanuk/core/CappucinoCoffee.java new file mode 100644 index 000000000..fa1a52c17 --- /dev/null +++ b/src/main/java/com/booleanuk/core/CappucinoCoffee.java @@ -0,0 +1,7 @@ +package com.booleanuk.core; + +public class CappucinoCoffee extends Coffee{ + public CappucinoCoffee(Double price, String abbreviation, String name, String typeOfItem){ + super(price, abbreviation, name, typeOfItem); + } +} diff --git a/src/main/java/com/booleanuk/core/CheeseFilling.java b/src/main/java/com/booleanuk/core/CheeseFilling.java new file mode 100644 index 000000000..6acbedd2f --- /dev/null +++ b/src/main/java/com/booleanuk/core/CheeseFilling.java @@ -0,0 +1,7 @@ +package com.booleanuk.core; + +public class CheeseFilling extends Filling{ + public CheeseFilling(Double price, String abbreviation, String name, String typeOfItem){ + super(price, abbreviation, name, typeOfItem); + } +} diff --git a/src/main/java/com/booleanuk/core/Coffee.java b/src/main/java/com/booleanuk/core/Coffee.java new file mode 100644 index 000000000..13b9270e1 --- /dev/null +++ b/src/main/java/com/booleanuk/core/Coffee.java @@ -0,0 +1,8 @@ +package com.booleanuk.core; + +public class Coffee extends Item{ + public Coffee(Double price, String abbreviation, String name, String typeOfItem){ + super(price, abbreviation, name, typeOfItem); + + } +} diff --git a/src/main/java/com/booleanuk/core/CreamCheeseFilling.java b/src/main/java/com/booleanuk/core/CreamCheeseFilling.java new file mode 100644 index 000000000..215663c89 --- /dev/null +++ b/src/main/java/com/booleanuk/core/CreamCheeseFilling.java @@ -0,0 +1,7 @@ +package com.booleanuk.core; + +public class CreamCheeseFilling extends Filling{ + public CreamCheeseFilling(Double price, String abbreviation, String name, String typeOfItem){ + super(price, abbreviation, name, typeOfItem); + } +} diff --git a/src/main/java/com/booleanuk/core/EggFilling.java b/src/main/java/com/booleanuk/core/EggFilling.java new file mode 100644 index 000000000..d7196dbf9 --- /dev/null +++ b/src/main/java/com/booleanuk/core/EggFilling.java @@ -0,0 +1,7 @@ +package com.booleanuk.core; + +public class EggFilling extends Filling{ + public EggFilling(Double price, String abbreviation, String name, String typeOfItem){ + super(price, abbreviation, name, typeOfItem); + } +} diff --git a/src/main/java/com/booleanuk/core/EverythingBagel.java b/src/main/java/com/booleanuk/core/EverythingBagel.java new file mode 100644 index 000000000..4a43c7c71 --- /dev/null +++ b/src/main/java/com/booleanuk/core/EverythingBagel.java @@ -0,0 +1,7 @@ +package com.booleanuk.core; + +public class EverythingBagel extends Bagel{ + public EverythingBagel(Double price, String abbreviation, String name, String typeOfItem){ + super(price, abbreviation, name, typeOfItem); + } +} diff --git a/src/main/java/com/booleanuk/core/Filling.java b/src/main/java/com/booleanuk/core/Filling.java new file mode 100644 index 000000000..cdab5d5ed --- /dev/null +++ b/src/main/java/com/booleanuk/core/Filling.java @@ -0,0 +1,8 @@ +package com.booleanuk.core; + +public class Filling extends Item{ + public Filling(Double price, String abbreviation, String name, String typeOfItem){ + super(price, abbreviation, name, typeOfItem); + + } +} diff --git a/src/main/java/com/booleanuk/core/HamFilling.java b/src/main/java/com/booleanuk/core/HamFilling.java new file mode 100644 index 000000000..847d5f317 --- /dev/null +++ b/src/main/java/com/booleanuk/core/HamFilling.java @@ -0,0 +1,7 @@ +package com.booleanuk.core; + +public class HamFilling extends Filling{ + public HamFilling(Double price, String abbreviation, String name, String typeOfItem){ + super(price, abbreviation, name, typeOfItem); + } +} diff --git a/src/main/java/com/booleanuk/core/Inventory.java b/src/main/java/com/booleanuk/core/Inventory.java new file mode 100644 index 000000000..375cdb479 --- /dev/null +++ b/src/main/java/com/booleanuk/core/Inventory.java @@ -0,0 +1,4 @@ +package com.booleanuk.core; + +public class Inventory { +} diff --git a/src/main/java/com/booleanuk/core/Item.java b/src/main/java/com/booleanuk/core/Item.java new file mode 100644 index 000000000..10b4baee3 --- /dev/null +++ b/src/main/java/com/booleanuk/core/Item.java @@ -0,0 +1,31 @@ +package com.booleanuk.core; + +public class Item { + private Double price; + private String abbreviation; + private String name; + private String typeOfItem; + + public Item(Double price, String abbreviation, String name, String typeOfItem){ + this.price = price; + this.abbreviation = abbreviation; + this.name = name; + this.typeOfItem = typeOfItem; + } + + public String getTypeOfItem() { + return typeOfItem; + } + + public Double getPrice() { + return price; + } + + public String getAbbreviation() { + return abbreviation; + } + + public String getName() { + return name; + } +} diff --git a/src/main/java/com/booleanuk/core/LatteCoffee.java b/src/main/java/com/booleanuk/core/LatteCoffee.java new file mode 100644 index 000000000..a4e99bd1c --- /dev/null +++ b/src/main/java/com/booleanuk/core/LatteCoffee.java @@ -0,0 +1,7 @@ +package com.booleanuk.core; + +public class LatteCoffee extends Coffee{ + public LatteCoffee(Double price, String abbreviation, String name, String typeOfItem){ + super(price, abbreviation, name, typeOfItem); + } +} diff --git a/src/main/java/com/booleanuk/core/Menu.java b/src/main/java/com/booleanuk/core/Menu.java new file mode 100644 index 000000000..0486fc314 --- /dev/null +++ b/src/main/java/com/booleanuk/core/Menu.java @@ -0,0 +1,41 @@ +package com.booleanuk.core; + +import java.util.ArrayList; + +public class Menu { + private ArrayList itemsOnMenu; + + public Menu(ArrayList itemsOnMenu){ + this.itemsOnMenu = itemsOnMenu; + } + + public String seePrice(Item itemToCheck){ + for(Item anItem : itemsOnMenu){ + if(anItem.getName().equals(itemToCheck.getName())){ + return "The item costs: " + itemToCheck.getPrice(); + } + } + + return "Item dont exist on the menu!"; + } + + public String showAllFillingsWithCosts(){ + String allFillingsWithPrices = ""; + for(Item anItem : this.itemsOnMenu){ + if(anItem.getTypeOfItem().equals("Filling")){ + allFillingsWithPrices += anItem.getName() + ", " + anItem.getPrice() + "$\n"; + } + } + return allFillingsWithPrices; + } + + + public Boolean isContainedInInventory(Item itemToCheck){ + for(Item anItem : itemsOnMenu){ + if(anItem.getName().equals(itemToCheck.getName())){ + return true; + } + } + return false; + } +} diff --git a/src/main/java/com/booleanuk/core/OnionBagel.java b/src/main/java/com/booleanuk/core/OnionBagel.java new file mode 100644 index 000000000..be8d46e7e --- /dev/null +++ b/src/main/java/com/booleanuk/core/OnionBagel.java @@ -0,0 +1,7 @@ +package com.booleanuk.core; + +public class OnionBagel extends Bagel{ + public OnionBagel(Double price, String abbreviation, String name, String typeOfItem){ + super(price, abbreviation, name, typeOfItem); + } +} diff --git a/src/main/java/com/booleanuk/core/PlainBagel.java b/src/main/java/com/booleanuk/core/PlainBagel.java new file mode 100644 index 000000000..abf22e438 --- /dev/null +++ b/src/main/java/com/booleanuk/core/PlainBagel.java @@ -0,0 +1,7 @@ +package com.booleanuk.core; + +public class PlainBagel extends Bagel{ + public PlainBagel(Double price, String abbreviation, String name, String typeOfItem){ + super(price, abbreviation, name, typeOfItem); + } +} diff --git a/src/main/java/com/booleanuk/core/SesameBagel.java b/src/main/java/com/booleanuk/core/SesameBagel.java new file mode 100644 index 000000000..0b2299cfa --- /dev/null +++ b/src/main/java/com/booleanuk/core/SesameBagel.java @@ -0,0 +1,7 @@ +package com.booleanuk.core; + +public class SesameBagel extends Bagel{ + public SesameBagel(Double price, String abbreviation, String name, String typeOfItem){ + super(price, abbreviation, name, typeOfItem); + } +} diff --git a/src/main/java/com/booleanuk/core/SmokedSalmonFilling.java b/src/main/java/com/booleanuk/core/SmokedSalmonFilling.java new file mode 100644 index 000000000..d61911f58 --- /dev/null +++ b/src/main/java/com/booleanuk/core/SmokedSalmonFilling.java @@ -0,0 +1,7 @@ +package com.booleanuk.core; + +public class SmokedSalmonFilling extends Filling{ + public SmokedSalmonFilling(Double price, String abbreviation, String name, String typeOfItem){ + super(price, abbreviation, name, typeOfItem); + } +} diff --git a/src/main/java/com/booleanuk/core/WhiteCoffee.java b/src/main/java/com/booleanuk/core/WhiteCoffee.java new file mode 100644 index 000000000..c25d6e220 --- /dev/null +++ b/src/main/java/com/booleanuk/core/WhiteCoffee.java @@ -0,0 +1,7 @@ +package com.booleanuk.core; + +public class WhiteCoffee extends Coffee{ + public WhiteCoffee(Double price, String abbreviation, String name, String typeOfItem){ + super(price, abbreviation, name, typeOfItem); + } +} diff --git a/src/main/java/com/booleanuk/extension/ExtensionBasket.java b/src/main/java/com/booleanuk/extension/ExtensionBasket.java new file mode 100644 index 000000000..4a91fe609 --- /dev/null +++ b/src/main/java/com/booleanuk/extension/ExtensionBasket.java @@ -0,0 +1,98 @@ +package com.booleanuk.extension; + +import com.booleanuk.core.Item; + +import java.util.ArrayList; + +public class ExtensionBasket { + private ArrayList itemsInBasket; + private int size; + + public ExtensionBasket(ArrayList itemsInBasket, int size){ + this.itemsInBasket = itemsInBasket; + this.size = size; + } + + public double totalCostWithDiscounts(){ + double totalCost = 0; + + int numOnionBagel = 0; + int numPlainBagel = 0; + int numEverythingBagel = 0; + int numSesameBagel = 0; + int numBagel = 0; + int numCoffee = 0; + + for(Item item : itemsInBasket){ + if(item.getAbbreviation().equals("BGL0")){ + numBagel++; + numOnionBagel++; + if(numOnionBagel == 12){ + numOnionBagel = 0; + totalCost -= 5*item.getPrice(); + totalCost += 1.50; + } else if (numOnionBagel == 6) { + totalCost -= 5*item.getPrice(); + totalCost += 2.49; + } else { + totalCost += item.getPrice(); + } + + } else if (item.getAbbreviation().equals("BGLP")) { + numBagel++; + numPlainBagel++; + if(numPlainBagel == 12){ + numPlainBagel = 0; + totalCost -= 5*item.getPrice(); + totalCost += 1.50; + } else if (numPlainBagel == 6) { + totalCost -= 5*item.getPrice(); + totalCost += 2.49; + } else { + totalCost += item.getPrice(); + } + + } else if (item.getAbbreviation().equals("BGLE")) { + numBagel++; + numEverythingBagel++; + if(numEverythingBagel == 12){ + numEverythingBagel = 0; + totalCost -= 5*item.getPrice(); + totalCost += 1.50; + } else if (numEverythingBagel == 6) { + totalCost -= 5*item.getPrice(); + totalCost += 2.49; + } else { + totalCost += item.getPrice(); + } + + } else if (item.getAbbreviation().equals("BGLS")) { + numBagel++; + numSesameBagel++; + if(numSesameBagel == 12){ + numSesameBagel = 0; + totalCost -= 5*item.getPrice(); + totalCost += 1.50; + } else if (numSesameBagel == 6) { + totalCost -= 5*item.getPrice(); + totalCost += 2.49; + } else { + totalCost += item.getPrice(); + } + + } else if (item.getAbbreviation().contains("COF")) { + numCoffee++; + totalCost += item.getPrice(); + } else{ + totalCost += item.getPrice(); + } + + + } + if(numBagel == 1 && numCoffee == 1){ + totalCost = 1.25; + } + double roundOff = Math.round(totalCost * 100.0) / 100.0; + return roundOff; + } +} diff --git a/src/main/java/com/booleanuk/extension/ExtensionReceipt.java b/src/main/java/com/booleanuk/extension/ExtensionReceipt.java new file mode 100644 index 000000000..8c746b1ec --- /dev/null +++ b/src/main/java/com/booleanuk/extension/ExtensionReceipt.java @@ -0,0 +1,174 @@ +package com.booleanuk.extension; + +import com.booleanuk.core.Item; + +import java.text.SimpleDateFormat; +import java.util.*; + +public class ExtensionReceipt { + HashMap itemsThatArePurchased; + String dateOfPurchase; + + public ExtensionReceipt(HashMap itemsThatArePurchased){ + this.itemsThatArePurchased = itemsThatArePurchased; + + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + this.dateOfPurchase = sdf.format(new Date()); + } + + public double totalCostWithDiscounts(){ + double totalCost = 0; + + int numOnionBagel = 0; + int numPlainBagel = 0; + int numEverythingBagel = 0; + int numSesameBagel = 0; + int numBagel = 0; + int numCoffee = 0; + + for(Item item : itemsThatArePurchased.keySet()){ + if(item.getAbbreviation() == "BGLO"){ + for(int i = 0; i < itemsThatArePurchased.get(item); i++){ + numBagel++; + numOnionBagel++; + if(numOnionBagel == 12){ + numOnionBagel = 0; + totalCost -= 5*item.getPrice(); + totalCost += 1.50; + } else if (numOnionBagel == 6) { + totalCost -= 5*item.getPrice(); + totalCost += 2.49; + } else { + totalCost += item.getPrice(); + } + } + + } else if (item.getAbbreviation() == "BGLP") { + for(int i = 0; i < itemsThatArePurchased.get(item); i++){ + numBagel++; + numPlainBagel++; + if(numPlainBagel == 12){ + numPlainBagel = 0; + totalCost -= 5*item.getPrice(); + totalCost += 1.50; + } else if (numPlainBagel == 6) { + totalCost -= 5*item.getPrice(); + totalCost += 2.49; + } else { + totalCost += item.getPrice(); + } + } + + } else if (item.getAbbreviation() == "BGLE") { + for(int i = 0; i < itemsThatArePurchased.get(item); i++){ + numBagel++; + numEverythingBagel++; + if(numEverythingBagel == 12){ + numEverythingBagel = 0; + totalCost -= 5*item.getPrice(); + totalCost += 1.50; + } else if (numEverythingBagel == 6) { + totalCost -= 5*item.getPrice(); + totalCost += 2.49; + } else { + totalCost += item.getPrice(); + } + } + + } else if (item.getAbbreviation() == "BGLS") { + for(int i = 0; i < itemsThatArePurchased.get(item); i++){ + numBagel++; + numSesameBagel++; + if(numSesameBagel == 12){ + numSesameBagel = 0; + totalCost -= 5*item.getPrice(); + totalCost += 1.50; + } else if (numSesameBagel == 6) { + totalCost -= 5*item.getPrice(); + totalCost += 2.49; + } else { + totalCost += item.getPrice(); + } + } + + } else if (item.getAbbreviation().contains("COF")) { + numCoffee = itemsThatArePurchased.get(item); + totalCost += item.getPrice()*itemsThatArePurchased.get(item); + } else{ + totalCost += item.getPrice(); + } + + + } + if(numBagel == 1 && numCoffee == 1){ + totalCost = 1.25; + } + + return Math.round(totalCost * 100.0) / 100.0; + } + + + + + public double costWithDiscounts(Item itemToCheck, int quantity){ + int numBagel = 0; + double cost = 0; + + if(itemToCheck.getAbbreviation().contains("BGL")){ + + for(int i = 0; i < quantity; i++){ + numBagel++; + if(numBagel == 12){ + numBagel = 0; + cost -= 5*itemToCheck.getPrice(); + cost += 1.50; + } else if (numBagel == 6) { + cost -= 5*itemToCheck.getPrice(); + cost += 2.49; + } else { + cost += itemToCheck.getPrice(); + } + } + } else { + cost += itemToCheck.getPrice()*quantity; + } + + return Math.round(cost * 100.0) / 100.0; + } + + + + + + + + public String printReceipt(){ + ArrayList keys = new ArrayList<>(itemsThatArePurchased.keySet()); + Collections.sort(keys, new Comparator() { + @Override + public int compare(Item o1, Item o2) { + return o1.getAbbreviation().compareTo(o2.getAbbreviation()); + } + }); + + StringBuilder stringBuilder = new StringBuilder(); + stringBuilder.append(" ~~~ Bob's Bagels ~~~ \n\n"); + stringBuilder.append(" "+dateOfPurchase); + stringBuilder.append("\n----------------------------\n"); + + for(Item anItem : keys){ + double price = costWithDiscounts(anItem, itemsThatArePurchased.get(anItem)); + stringBuilder.append(anItem.getName() + " " + anItem.getTypeOfItem() + " " + itemsThatArePurchased.get(anItem) + " £" + price + "\n"); + } + + stringBuilder.append("\n----------------------------\n"); + stringBuilder.append("Total " + "£" + totalCostWithDiscounts() + "\n"); + + + stringBuilder.append(" Thank you\n"); + stringBuilder.append(" for your order!"); + + System.out.println(stringBuilder); + return stringBuilder.toString(); + } +} diff --git a/src/test/java/com/booleanuk/core/BasketTest.java b/src/test/java/com/booleanuk/core/BasketTest.java new file mode 100644 index 000000000..74ae408dc --- /dev/null +++ b/src/test/java/com/booleanuk/core/BasketTest.java @@ -0,0 +1,125 @@ +package com.booleanuk.core; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +import java.util.ArrayList; + +public class BasketTest { + + private ArrayList itemsInBasket = new ArrayList<>(){{ + // Adding the bagels + Item onionBagel1 = new OnionBagel(0.49, "BGLO", "Onion", "Bagel") {}; + add(onionBagel1); + Item onionBagel2 = new OnionBagel(0.49, "BGLO", "Onion", "Bagel") {}; + add(onionBagel2); + + Item plainBagel1 = new PlainBagel(0.39, "BGLP", "Plain", "Bagel") {}; + add(plainBagel1); + Item plainBagel2 = new PlainBagel(0.39, "BGLP", "Plain", "Bagel") {}; + add(plainBagel2); + Item plainBagel3 = new PlainBagel(0.39, "BGLP", "Plain", "Bagel") {}; + add(plainBagel3); + Item plainBagel4 = new PlainBagel(0.39, "BGLP", "Plain", "Bagel") {}; + add(plainBagel4); + Item plainBagel5 = new PlainBagel(0.39, "BGLP", "Plain", "Bagel") {}; + add(plainBagel5); + Item plainBagel6 = new PlainBagel(0.39, "BGLP", "Plain", "Bagel") {}; + add(plainBagel6); + Item plainBagel7 = new PlainBagel(0.39, "BGLP", "Plain", "Bagel") {}; + add(plainBagel7); + Item plainBagel8 = new PlainBagel(0.39, "BGLP", "Plain", "Bagel") {}; + add(plainBagel8); + Item plainBagel9 = new PlainBagel(0.39, "BGLP", "Plain", "Bagel") {}; + add(plainBagel9); + Item plainBagel10 = new PlainBagel(0.39, "BGLP", "Plain", "Bagel") {}; + add(plainBagel10); + Item plainBagel11 = new PlainBagel(0.39, "BGLP", "Plain", "Bagel") {}; + add(plainBagel11); + Item plainBagel12 = new PlainBagel(0.39, "BGLP", "Plain", "Bagel") {}; + add(plainBagel12); + + Item everythingBagel1 = new EverythingBagel(0.49, "BGLE", "Everything", "Bagel") {}; + add(everythingBagel1); + Item everythingBagel2 = new EverythingBagel(0.49, "BGLE", "Everything", "Bagel") {}; + add(everythingBagel2); + Item everythingBagel3 = new EverythingBagel(0.49, "BGLE", "Everything", "Bagel") {}; + add(everythingBagel3); + Item everythingBagel4 = new EverythingBagel(0.49, "BGLE", "Everything", "Bagel") {}; + add(everythingBagel4); + Item everythingBagel5 = new EverythingBagel(0.49, "BGLE", "Everything", "Bagel") {}; + add(everythingBagel5); + Item everythingBagel6 = new EverythingBagel(0.49, "BGLE", "Everything", "Bagel") {}; + add(everythingBagel6); + + Item blackCoffee1 = new BlackCoffee(0.99, "COFB", "Black", "Coffee"){}; + add(blackCoffee1); + Item blackCoffee2 = new BlackCoffee(0.99, "COFB", "Black", "Coffee"){}; + add(blackCoffee2); + Item blackCoffee3 = new BlackCoffee(0.99, "COFB", "Black", "Coffee"){}; + add(blackCoffee3); + }}; + + @Test + public void basketIsFullWhenAdding(){ + Basket basket = new Basket(itemsInBasket, 23); + Item itemToAdd = new OnionBagel(0.49, "BGLO", "Onion", "Bagel"){}; + + Assertions.assertEquals("Basket is full!", basket.addItem(itemToAdd)); + } + + @Test + public void basketIsNotFullWhenAdding(){ + Basket basket = new Basket(itemsInBasket, 25); + Item itemToAdd = new OnionBagel(0.49, "BGLO", "Onion", "Bagel"){}; + + Assertions.assertEquals(itemToAdd.getName() + " was added to your basket!", basket.addItem(itemToAdd)); + } + + @Test + public void removingItemThatDoesNotExistInBasket(){ + Basket basket = new Basket(itemsInBasket, 25); + Item itemToRemove = new OnionBagel(0.49, "BGLO", "Tomato", "Bagel"){}; + + Assertions.assertEquals("Item do not exist in basket!", basket.removeItem(itemToRemove)); + } + + @Test + public void removingItemThatDoExistInBasket(){ + Basket basket = new Basket(itemsInBasket, 25); + Item itemToRemove = new OnionBagel(0.49, "BGLO", "Onion", "Bagel"){}; + + Assertions.assertEquals(itemToRemove.getName() + " was removed from the basket!", basket.removeItem(itemToRemove)); + } + + @Test + public void enteringAcceptableBasketSize(){ + Basket basket = new Basket(itemsInBasket, 25); + + Assertions.assertTrue(basket.changeSizeOfBasket(24)); + } + + @Test + public void enteringANonAcceptableBasketSize(){ + Basket basket = new Basket(itemsInBasket, 25); + + Assertions.assertFalse(basket.changeSizeOfBasket(5)); + } + + + @Test + public void totalCostOfBasketWhenItIsNotEmpty(){ + Basket basket = new Basket(itemsInBasket, 25); + + Assertions.assertEquals(11.57, basket.totalCost()); + } + + @Test + public void totalCostOfBasketWhenItIsEmpty(){ + ArrayList emptyList = new ArrayList<>(); + Basket basket = new Basket(emptyList, 6); + + Assertions.assertEquals(0, basket.totalCost()); + } + +} diff --git a/src/test/java/com/booleanuk/core/InventoryTest.java b/src/test/java/com/booleanuk/core/InventoryTest.java new file mode 100644 index 000000000..4b67d33d3 --- /dev/null +++ b/src/test/java/com/booleanuk/core/InventoryTest.java @@ -0,0 +1,4 @@ +package com.booleanuk.core; + +public class InventoryTest { +} diff --git a/src/test/java/com/booleanuk/core/ItemTest.java b/src/test/java/com/booleanuk/core/ItemTest.java new file mode 100644 index 000000000..be04480f7 --- /dev/null +++ b/src/test/java/com/booleanuk/core/ItemTest.java @@ -0,0 +1,4 @@ +package com.booleanuk.core; + +public class ItemTest { +} diff --git a/src/test/java/com/booleanuk/core/MenuTest.java b/src/test/java/com/booleanuk/core/MenuTest.java new file mode 100644 index 000000000..117dcd079 --- /dev/null +++ b/src/test/java/com/booleanuk/core/MenuTest.java @@ -0,0 +1,98 @@ +package com.booleanuk.core; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +import java.util.ArrayList; + +public class MenuTest { + + private ArrayList itemsOnMenu = new ArrayList<>(){{ + // Adding the bagels + Item onionBagel = new OnionBagel(0.49, "BGLO", "Onion", "Bagel"){}; + add(onionBagel); + Item plainBagel = new PlainBagel(0.39, "BGLP", "Plain", "Bagel"){}; + add(plainBagel); + Item everythingBagel = new EverythingBagel(0.49, "BGLE", "Everything", "Bagel"){}; + add(everythingBagel); + Item sesameBagel = new SesameBagel(0.49, "BGLS", "Sesame", "Bagel"){}; + add(sesameBagel); + + // Adding the coffees + Item blackCoffee = new BlackCoffee(0.99, "COFB", "Black", "Coffee"){}; + add(blackCoffee); + Item whiteCoffee = new WhiteCoffee(1.19, "COFW", "White", "Coffee"){}; + add(whiteCoffee); + Item cappucinoCoffee = new CappucinoCoffee(1.29, "COFC", "Cappuccino", "Coffee"){}; + add(cappucinoCoffee); + Item latteCoffee = new LatteCoffee(1.29, "COFL", "Latte", "Coffee"){}; + add(latteCoffee); + + // Adding the fillings + Item baconFilling = new BaconFilling(0.12, "FILB", "Bacon", "Filling"){}; + add(baconFilling); + Item eggFilling = new EggFilling(0.12, "FILE", "Egg", "Filling"){}; + add(eggFilling); + Item cheeseFilling = new CheeseFilling(0.12, "FILC", "Cheese", "Filling"){}; + add(cheeseFilling); + Item creamCheeseFilling = new CreamCheeseFilling(0.12, "FILX", "Cream Cheese", "Filling"){}; + add(creamCheeseFilling); + Item smokedSalmonFilling = new SmokedSalmonFilling(0.12, "FILS", "Smoked Salmon", "Filling"){}; + add(smokedSalmonFilling); + Item hamFilling = new HamFilling(0.12, "FILH", "Ham", "Filling"){}; + add(hamFilling); + }}; + + @Test + public void itemDontExistOnMenuSeePrice(){ + Menu menu = new Menu(itemsOnMenu); + Item itemToCheck = new Item(0.10, "abc", "apple", "Filling"); + + Assertions.assertEquals("Item dont exist on the menu!", menu.seePrice(itemToCheck)); + } + + @Test + public void itemExistOnMenuSeePrice(){ + Menu menu = new Menu(itemsOnMenu); + Item itemToCheck = new OnionBagel(0.49, "BGLO", "Onion", "Bagel"){}; + + Assertions.assertEquals("The item costs: " + itemToCheck.getPrice(), menu.seePrice(itemToCheck)); + } + + + + + + @Test + public void allFillingsAreReturned(){ + Menu menu = new Menu(itemsOnMenu); + String allFillingsWithPrices = "Bacon, 0.12$" + "\n" + + "Egg, 0.12$" + "\n" + + "Cheese, 0.12$" + "\n" + + "Cream Cheese, 0.12$" + "\n" + + "Smoked Salmon, 0.12$" + "\n" + + "Ham, 0.12$" + "\n"; + + Assertions.assertEquals(allFillingsWithPrices, menu.showAllFillingsWithCosts()); + } + + + + + @Test + public void itemDontExistOnMenu(){ + Menu menu = new Menu(itemsOnMenu); + Item itemToCheck = new Item(0.10, "abc", "apple", "Filling"); + + Assertions.assertFalse(menu.isContainedInInventory(itemToCheck)); + } + + @Test + public void itemExistOnMenu(){ + Menu menu = new Menu(itemsOnMenu); + Item itemToCheck = new OnionBagel(0.49, "BGLO", "Onion", "Bagel"){}; + + Assertions.assertTrue(menu.isContainedInInventory(itemToCheck)); + } + +} diff --git a/src/test/java/com/booleanuk/extension/ExtensionBasketTest.java b/src/test/java/com/booleanuk/extension/ExtensionBasketTest.java new file mode 100644 index 000000000..7303d9fbf --- /dev/null +++ b/src/test/java/com/booleanuk/extension/ExtensionBasketTest.java @@ -0,0 +1,103 @@ +package com.booleanuk.extension; + +import com.booleanuk.core.*; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +import java.util.ArrayList; + +public class ExtensionBasketTest { + private ArrayList itemsInBasket = new ArrayList<>(){{ + // Adding the bagels + Item onionBagel1 = new OnionBagel(0.49, "BGLO", "Onion", "Bagel") {}; + add(onionBagel1); + Item onionBagel2 = new OnionBagel(0.49, "BGLO", "Onion", "Bagel") {}; + add(onionBagel2); + + Item plainBagel1 = new PlainBagel(0.39, "BGLP", "Plain", "Bagel") {}; + add(plainBagel1); + Item plainBagel2 = new PlainBagel(0.39, "BGLP", "Plain", "Bagel") {}; + add(plainBagel2); + Item plainBagel3 = new PlainBagel(0.39, "BGLP", "Plain", "Bagel") {}; + add(plainBagel3); + Item plainBagel4 = new PlainBagel(0.39, "BGLP", "Plain", "Bagel") {}; + add(plainBagel4); + Item plainBagel5 = new PlainBagel(0.39, "BGLP", "Plain", "Bagel") {}; + add(plainBagel5); + Item plainBagel6 = new PlainBagel(0.39, "BGLP", "Plain", "Bagel") {}; + add(plainBagel6); + Item plainBagel7 = new PlainBagel(0.39, "BGLP", "Plain", "Bagel") {}; + add(plainBagel7); + Item plainBagel8 = new PlainBagel(0.39, "BGLP", "Plain", "Bagel") {}; + add(plainBagel8); + Item plainBagel9 = new PlainBagel(0.39, "BGLP", "Plain", "Bagel") {}; + add(plainBagel9); + Item plainBagel10 = new PlainBagel(0.39, "BGLP", "Plain", "Bagel") {}; + add(plainBagel10); + Item plainBagel11 = new PlainBagel(0.39, "BGLP", "Plain", "Bagel") {}; + add(plainBagel11); + Item plainBagel12 = new PlainBagel(0.39, "BGLP", "Plain", "Bagel") {}; + add(plainBagel12); + + Item everythingBagel1 = new EverythingBagel(0.49, "BGLE", "Everything", "Bagel") {}; + add(everythingBagel1); + Item everythingBagel2 = new EverythingBagel(0.49, "BGLE", "Everything", "Bagel") {}; + add(everythingBagel2); + Item everythingBagel3 = new EverythingBagel(0.49, "BGLE", "Everything", "Bagel") {}; + add(everythingBagel3); + Item everythingBagel4 = new EverythingBagel(0.49, "BGLE", "Everything", "Bagel") {}; + add(everythingBagel4); + Item everythingBagel5 = new EverythingBagel(0.49, "BGLE", "Everything", "Bagel") {}; + add(everythingBagel5); + Item everythingBagel6 = new EverythingBagel(0.49, "BGLE", "Everything", "Bagel") {}; + add(everythingBagel6); + + Item blackCoffee1 = new BlackCoffee(0.99, "COFB", "Black", "Coffee"){}; + add(blackCoffee1); + Item blackCoffee2 = new BlackCoffee(0.99, "COFB", "Black", "Coffee"){}; + add(blackCoffee2); + Item blackCoffee3 = new BlackCoffee(0.99, "COFB", "Black", "Coffee"){}; + add(blackCoffee3); + }}; + + // Extension 1 + @Test + public void discountsAreRecieved(){ + ExtensionBasket basket = new ExtensionBasket(itemsInBasket, 25); + + Assertions.assertEquals(10.43, basket.totalCostWithDiscounts()); + } + + @Test + public void discountsAreNotRecieved(){ + ArrayList listOfItems = new ArrayList<>(){{ + Item plainBagel1 = new PlainBagel(0.39, "BGLP", "Plain", "Bagel") {}; + add(plainBagel1); + Item plainBagel2 = new PlainBagel(0.39, "BGLP", "Plain", "Bagel") {}; + add(plainBagel2); + Item plainBagel3 = new PlainBagel(0.39, "BGLP", "Plain", "Bagel") {}; + add(plainBagel3); + Item plainBagel4 = new PlainBagel(0.39, "BGLP", "Plain", "Bagel") {}; + add(plainBagel4); + Item plainBagel5 = new PlainBagel(0.39, "BGLP", "Plain", "Bagel") {}; + add(plainBagel5); + }}; + ExtensionBasket basket = new ExtensionBasket(listOfItems, 6); + + Assertions.assertEquals(1.95, basket.totalCostWithDiscounts()); + } + + @Test + public void coffeeAndBagelDiscountAreRecieved(){ + ArrayList listOfItems = new ArrayList<>(){{ + Item plainBagel = new PlainBagel(0.39, "BGLP", "Plain", "Bagel") {}; + add(plainBagel); + Item blackCoffee = new BlackCoffee(0.99, "COFB", "Black", "Coffee"){}; + add(blackCoffee); + }}; + ExtensionBasket basket = new ExtensionBasket(listOfItems, 6); + + Assertions.assertEquals(1.25, basket.totalCostWithDiscounts()); + } + +} diff --git a/src/test/java/com/booleanuk/extension/ExtensionReceiptTest.java b/src/test/java/com/booleanuk/extension/ExtensionReceiptTest.java new file mode 100644 index 000000000..d12e91568 --- /dev/null +++ b/src/test/java/com/booleanuk/extension/ExtensionReceiptTest.java @@ -0,0 +1,106 @@ +package com.booleanuk.extension; + +import com.booleanuk.core.*; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Date; +import java.util.HashMap; + +public class ExtensionReceiptTest { + private HashMap itemsThatArePurchased = new HashMap<>(){{ + // Adding the bagels + Item blackCoffee = new BlackCoffee(0.99, "COFB", "Black", "Coffee"){}; + put(blackCoffee, 3); + + Item onionBagel = new OnionBagel(0.49, "BGLO", "Onion", "Bagel") {}; + put(onionBagel, 2); + + Item everythingBagel = new EverythingBagel(0.49, "BGLE", "Everything", "Bagel") {}; + put(everythingBagel, 6); + + Item plainBagel = new PlainBagel(0.39, "BGLP", "Plain", "Bagel") {}; + put(plainBagel, 12); + + }}; + + // testing total cost once again since I had to adjust it when using a HashMap instead of arraylist + @Test + public void discountsAreRecieved(){ + ExtensionReceipt receipt = new ExtensionReceipt(itemsThatArePurchased); + + Assertions.assertEquals(10.43, receipt.totalCostWithDiscounts()); + } + + // testing total cost once again since I had to adjust it when using a HashMap instead of arraylist + @Test + public void discountsAreNotRecieved(){ + HashMap listOfItems = new HashMap<>(){{ + Item plainBagel = new PlainBagel(0.39, "BGLP", "Plain", "Bagel") {}; + put(plainBagel, 5); + }}; + + ExtensionReceipt receipt = new ExtensionReceipt(listOfItems); + + Assertions.assertEquals(1.95, receipt.totalCostWithDiscounts()); + } + + // testing total cost once again since I had to adjust it when using a HashMap instead of arraylist + @Test + public void coffeeAndBagelDiscountAreRecieved(){ + HashMap listOfItems = new HashMap<>(){{ + Item plainBagel = new PlainBagel(0.39, "BGLP", "Plain", "Bagel") {}; + put(plainBagel, 1); + Item blackCoffee = new BlackCoffee(0.99, "COFB", "Black", "Coffee"){}; + put(blackCoffee, 1); + }}; + + ExtensionReceipt receipt = new ExtensionReceipt(listOfItems); + + Assertions.assertEquals(1.25, receipt.totalCostWithDiscounts()); + } + + +// EXTENSION 2 + @Test + public void correctReceiptIsPrinted(){ + ExtensionReceipt receipt = new ExtensionReceipt(itemsThatArePurchased); + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + String dateOfPurchase = sdf.format(new Date()); + + String desiredOutput = " ~~~ Bob's Bagels ~~~ \n\n" + + " " +dateOfPurchase + + "\n----------------------------\n" + + "Everything Bagel 6 £2.49\n" + + "Onion Bagel 2 £0.98\n" + + "Plain Bagel 12 £3.99\n" + + "Black Coffee 3 £2.97\n" + + "\n----------------------------\n" + + "Total £10.43\n" + + " Thank you\n" + + " for your order!"; + + + Assertions.assertEquals(desiredOutput, receipt.printReceipt()); + } + + + @Test + public void discountsForSpecificItemAreReceived(){ + Item onionBagel = new OnionBagel(0.49, "BGLO", "Onion", "Bagel") {}; + ExtensionReceipt receipt = new ExtensionReceipt(itemsThatArePurchased); + + Assertions.assertEquals(2.49, receipt.costWithDiscounts(onionBagel, 6)); + } + + @Test + public void discountsForSpecificItemAreNotReceived(){ + Item onionBagel = new OnionBagel(0.49, "BGLO", "Onion", "Bagel") {}; + ExtensionReceipt receipt = new ExtensionReceipt(itemsThatArePurchased); + + + Assertions.assertEquals(2.45, receipt.costWithDiscounts(onionBagel, 5)); + } +}