diff --git a/Screenshot 2025-01-15 002216.png b/Screenshot 2025-01-15 002216.png new file mode 100644 index 000000000..4ace76b70 Binary files /dev/null and b/Screenshot 2025-01-15 002216.png differ diff --git a/domain-model.md b/domain-model.md new file mode 100644 index 000000000..022f065e2 --- /dev/null +++ b/domain-model.md @@ -0,0 +1,88 @@ +# Bagels domain model + + +## OrderManager class ? +| Methods | Member variables | Scenario | Result | +|------------------------------------|------------------|-------------------------------|---------------------------| +| | String name? | | | +| | Basket basket | | | +| addItemToBasket(Item item) | | basket is not full | string itemAddedMessage | +| | | basket is full | string fullBasketMessage | +| | | item is in menu/inventory | void | +| | | item is not in menu/inventory | string notInStockMessage | +| removeItemFromBasket(Item item) | | item is in basket | string itemRemovedMessage | +| | | item is not in basket | string errorMessage | +| changeBasketCapacity(int capacity) | | capacity was updated | true / string? | +| | | capacity was not updated | false / string? | +| | | | double totalPrice | +| | | | | +| | | | String itemsInInventory | +| | | | | +| | | | | + +## Basket class + +| Methods | Member variables | Scenario | Results | +|------------------------------------|----------------------------|------------------|---------| +| | ArrayList items | | | +| | int capacity | | | +| addItem(Item item) | | item added | true | +| | | item not added | false | +| getTotalCost(ArrayList) | | gets total cost | int | +| deleteItem(Item item) | | item deleted | true | +| | | item not deleted | false | +| setCapacity(int) | | | | +| | | | | + + +## Item class + +| Methods | member variables | scenario | result | +|------------|------------------|--------------|--------| +| getSKU | String SKU | gets SKU | string | +| getPrice | double price | gets price | double | +| getName | String name | gets name | string | +| getVariant | String variant | gets variant | string | + +## Inventory class + +| Methods | member variables | scenario | result | +|-----------------------|----------------------------------|-------------------------------|------------------------| +| | Map items | | | +| getItem(String SKU) | | item exists | Item object or null | +| | | item does not exist | null | +| printItem(String SKU) | | inventory has items | string of items | +| | | inventory does not have items | string inventory empty | + + +## Bagel class inherits from item + + +| Methods | member variables | scenario | result | +|--------------------------------------------------------------|---------------------|----------|------------------| +| | String SKU | | string | +| | double price | | double | +| | String name="Bagel" | | string | +| | String variant | | string | +| Constructor(Bagel(String SKU, String variant, double price)) | | | new bagel object | + + +## Filling class inherits from item + +| Methods | member variables | scenario | result | +|----------------------------------------------------------------|-----------------------|----------|--------------------| +| | String SKU | | string | +| | double price | | double | +| | String name="Filling" | | string | +| | String variant | | string | +| Constructor(Filling(String SKU, String variant, double price)) | | | new filling object | + +## Coffee class inherits from item + +| Methods | member variables | scenario | result | +|---------------------------------------------------------------|----------------------|----------|-------------------| +| | String SKU | | string | +| | double price | | double | +| | String name="Coffee" | | string | +| | String variant | | string | +| Constructor(Coffee(String SKU, String variant, double price)) | | | new coffee object | \ No newline at end of file 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..a95794255 --- /dev/null +++ b/src/main/java/com/booleanuk/core/Bagel.java @@ -0,0 +1,8 @@ +package com.booleanuk.core; + +public class Bagel extends Item{ + + public Bagel(String SKU, double price, String name, String variant) { + super(SKU, price, name, variant); + } +} 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..99d49e275 --- /dev/null +++ b/src/main/java/com/booleanuk/core/Basket.java @@ -0,0 +1,45 @@ +package com.booleanuk.core; + +import java.util.ArrayList; + +public class Basket { + private ArrayList basketItems; + private int capacity; + + + public Basket(ArrayList items) { + this.basketItems = items; + } + + public String addItem(Item item) { + if (!(basketItems.size() >= capacity)) { + basketItems.add(item); + return "Item added successfully!"; + } + return "Basket is full!"; + } + + public String removeItem(Item item) { + if (basketItems.contains(item)) { + basketItems.remove(item); + return "Item removed!"; + } + return "Could not remove - item was never in basket"; + } + + public double getTotalPrice(ArrayList items) { + double total = 0.0; + for (Item item : items) { + total += item.getPrice(); + } + return total; + } + + public int getCapacity() { + return capacity; + } + + public void setCapacity(int capacity) { + this.capacity = capacity; + } +} 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..86866c618 --- /dev/null +++ b/src/main/java/com/booleanuk/core/Coffee.java @@ -0,0 +1,7 @@ +package com.booleanuk.core; + +public class Coffee extends Item{ + public Coffee(String SKU, double price, String name, String variant) { + super(SKU, price, name, variant); + } +} 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..b7ceb520e --- /dev/null +++ b/src/main/java/com/booleanuk/core/Filling.java @@ -0,0 +1,7 @@ +package com.booleanuk.core; + +public class Filling extends Item{ + public Filling(String SKU, double price, String name, String variant) { + super(SKU, price, name, variant); + } +} 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..a67b8ae7b --- /dev/null +++ b/src/main/java/com/booleanuk/core/Inventory.java @@ -0,0 +1,33 @@ +package com.booleanuk.core; + +import java.util.ArrayList; +import java.util.HashMap; + +public class Inventory { + private HashMap inventoryItems; + + public Inventory(HashMap inventoryItems) { + this.inventoryItems = new HashMap<>(); + this.inventoryItems.put("BGLO", new Item("BGLO", 0.49, "Bagel", "Onion")); + this.inventoryItems.put("BGLP", new Item("BGLP", 0.39, "Bagel", "Plain")); + this.inventoryItems.put("BGLE", new Item("BGLE", 0.49, "Bagel", "Everything")); + this.inventoryItems.put("BGLS", new Item("BGLS", 0.49, "Bagel", "Sesame")); + this.inventoryItems.put("COFB", new Item("COFB", 0.99, "Coffee", "Black")); + this.inventoryItems.put("COFW", new Item("COFW", 1.19, "Coffee", "White")); + this.inventoryItems.put("COFC", new Item("COFC", 1.29, "Coffee", "Capuccino")); + this.inventoryItems.put("COFL", new Item("COFL", 1.29, "Coffee", "Latte")); + this.inventoryItems.put("FILB", new Item("FILB", 0.12, "Filling", "Bacon")); + this.inventoryItems.put("FILE", new Item("FILE", 0.12, "Filling", "Egg")); + this.inventoryItems.put("FILC", new Item("FILC", 0.12, "Filling", "Cheese")); + this.inventoryItems.put("FILX", new Item("FILX", 0.12, "Filling", "Cream Cheese")); + this.inventoryItems.put("FILS", new Item("FILS", 0.12, "Filling", "Smoked Salmon")); + this.inventoryItems.put("FILH", new Item("FILH", 0.12, "Filling", "Ham")); + } + + public boolean hasItem(String item) { + System.out.println(item); + System.out.println(inventoryItems); + return inventoryItems.containsKey(item); + } +} + 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..c8c8bc66e --- /dev/null +++ b/src/main/java/com/booleanuk/core/Item.java @@ -0,0 +1,32 @@ +package com.booleanuk.core; + +public class Item { + + private String SKU; + private double price; + private String name; + private 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 getSKU() { + return SKU; + } + + public double getPrice() { + return price; + } + + public String getName() { + return name; + } + + public String getVariant() { + return variant; + } +} diff --git a/src/test/java/com/booleanuk/core/BagelTest.java b/src/test/java/com/booleanuk/core/BagelTest.java new file mode 100644 index 000000000..2c561148f --- /dev/null +++ b/src/test/java/com/booleanuk/core/BagelTest.java @@ -0,0 +1,21 @@ +package com.booleanuk.core; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +public class BagelTest { + + @Test + public void testBagelCreation(){ + String SKU = "BGLS"; + double price = 0.49; + String name = "Bagel"; + String variant = "Sesame"; + Bagel bagel = new Bagel(SKU, price, name, variant); + + Assertions.assertEquals(SKU, bagel.getSKU()); + Assertions.assertEquals(price, bagel.getPrice()); + Assertions.assertEquals(name, bagel.getName()); + Assertions.assertEquals(variant, bagel.getVariant()); + } +} 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..afd9e9926 --- /dev/null +++ b/src/test/java/com/booleanuk/core/BasketTest.java @@ -0,0 +1,71 @@ +package com.booleanuk.core; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import java.util.ArrayList; + +public class BasketTest { + private Basket basket; + private Item bagel; + private Item coffee; + private Item filling; + + @BeforeEach + public void setUp() { + ArrayList basketItems = new ArrayList<>() {{ + add(bagel); + add(coffee); + add(filling); + }}; + basket = new Basket(basketItems); + basket.setCapacity(6); + bagel = new Item("BGLS", 0.49, "Bagel", "Sesame"); + coffee = new Item("COFB", 0.99, "Coffee" , "Black"); + filling = new Item("FILX", 0.12, "Filling", "Cream Cheese"); + } + + @Test + public void testAddItem() { + Assertions.assertEquals("Item added successfully!",basket.addItem(coffee)); + Assertions.assertEquals("Item added successfully!",basket.addItem(bagel)); + Assertions.assertEquals("Item added successfully!",basket.addItem(filling)); + } + + @Test + public void testAddItemToFullBasket() { + basket.setCapacity(2); + basket.addItem(bagel); + basket.addItem(filling); + + } + + @Test + public void testRemoveItem() { + basket.addItem(coffee); + basket.addItem(bagel); + Assertions.assertEquals("Item removed!",basket.removeItem(coffee)); + Assertions.assertEquals("Item removed!",basket.removeItem(bagel)); + Assertions.assertEquals("Could not remove - item was never in basket", basket.removeItem(filling)); + } + + @Test + public void testGetTotalPrice() { + ArrayList basketItems = new ArrayList<>() {{ + add(bagel); + add(coffee); + add(filling); + }}; + Assertions.assertEquals(1.60, basket.getTotalPrice(basketItems)); + } + + @Test + public void testSetCapacity(){ + basket.setCapacity(2); + basket.addItem(bagel); + basket.addItem(coffee); + Assertions.assertEquals("Basket is full!", basket.addItem(filling)); + } + +} diff --git a/src/test/java/com/booleanuk/core/CoffeeTest.java b/src/test/java/com/booleanuk/core/CoffeeTest.java new file mode 100644 index 000000000..7764e237a --- /dev/null +++ b/src/test/java/com/booleanuk/core/CoffeeTest.java @@ -0,0 +1,20 @@ +package com.booleanuk.core; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +public class CoffeeTest { + @Test + public void testCoffeeCreation(){ + String SKU = "COFB"; + double price = 0.99; + String name = "Coffee"; + String variant = "Black"; + Coffee coffee = new Coffee(SKU, price, name, variant); + + Assertions.assertEquals(SKU, coffee.getSKU()); + Assertions.assertEquals(price, coffee.getPrice()); + Assertions.assertEquals(name, coffee.getName()); + Assertions.assertEquals(variant, coffee.getVariant()); + } +} diff --git a/src/test/java/com/booleanuk/core/FillingTest.java b/src/test/java/com/booleanuk/core/FillingTest.java new file mode 100644 index 000000000..f319afbf5 --- /dev/null +++ b/src/test/java/com/booleanuk/core/FillingTest.java @@ -0,0 +1,20 @@ +package com.booleanuk.core; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +public class FillingTest { + @Test + public void testFillingCreation(){ + String SKU = "BGLS"; + double price = 0.49; + String name = "Bagel"; + String variant = "Sesame"; + Filling filling = new Filling(SKU, price, name, variant); + + Assertions.assertEquals(SKU, filling.getSKU()); + Assertions.assertEquals(price, filling.getPrice()); + Assertions.assertEquals(name, filling.getName()); + Assertions.assertEquals(variant, filling.getVariant()); + } +} 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..6dc61f4de --- /dev/null +++ b/src/test/java/com/booleanuk/core/InventoryTest.java @@ -0,0 +1,30 @@ +package com.booleanuk.core; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import java.util.HashMap; + +public class InventoryTest { + private Inventory inventory; + private Item itemB; + private Item itemC; + private Item itemF; + + @BeforeEach + public void setUp() { + HashMap inventoryItems = new HashMap<>() {{ + put("BGLS", itemB); + put("COFB", itemC); + }}; + inventory = new Inventory(inventoryItems); + itemB = new Item("BGLS", 0.49, "Bagel", "Sesame"); + itemC = new Item("COFB", 0.99, "Coffee" , "Black"); + } + + @Test + public void testPrintInventory() { + Assertions.assertEquals("BGLS, 0.49, Bagel, Sesame \n COFB, 0.99, Coffee, Black" ,inventory.printInventory()); + } +} 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..562c555b9 --- /dev/null +++ b/src/test/java/com/booleanuk/core/ItemTest.java @@ -0,0 +1,22 @@ +package com.booleanuk.core; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +public class ItemTest { + + @Test + public void testItemConstructor() { + String SKU = "BGLS"; + double price = 0.49; + String name = "Bagel"; + String variant = "Sesame"; + Item item = new Item(SKU, price, name, variant); + + Assertions.assertEquals(SKU, item.getSKU()); + Assertions.assertEquals(price, item.getPrice()); + Assertions.assertEquals(name, item.getName()); + Assertions.assertEquals(variant, item.getVariant()); + } + +}