diff --git a/exercise.main/Basket.cs b/exercise.main/Basket.cs new file mode 100644 index 00000000..13bf3896 --- /dev/null +++ b/exercise.main/Basket.cs @@ -0,0 +1,80 @@ + +namespace exercise; + +public class Basket +{ + public List Items { get; set; } = new List(); + public int MaxSize { get; set; } = 10; + + public void AddItem(Item item) + { + if (!IsBasketFull()) + { + Items.Add(item); + } + else + { + Console.WriteLine("Basket is full!"); + } + } + + public void RemoveItem(Item item) + { + Items.Remove(item); + } + + public bool IsBasketFull() + { + if (Items.Count >= MaxSize) + { + return true; + } + else + return false; + } + + public bool IsItemInBasket(Item item) + { + return Items.Contains(item); + } + + public decimal PriceInBasket() + { + decimal total = 0; + + // This part might not make it any cleaner, but ill keep it, not great since it only checks for one type of discount + var (fullSetsOfSix, singleBGLEPrice, remainingBGLE) = CheckforBGLE(); + + // Total for all bagels + total += fullSetsOfSix * 2.49m + remainingBGLE * singleBGLEPrice; + + // Total for all non-bagel items + total += Items.Where(item => !item.SKU.StartsWith("BGLE")) + .Sum(item => item.Price); + + return total; + } + + private (int fullSetsOfSix, decimal singleBGLEPrice, int remainingBGLE) CheckforBGLE() + { + int BGLECount = Items.Count(item => item.SKU.StartsWith("BGLE")); + int fullSetsOfSix = BGLECount / 6; + int remainingBGLE = BGLECount % 6; + + decimal singleBGLEPrice = Items.FirstOrDefault(item => item.SKU.StartsWith("BGLE")).Price; + + return (fullSetsOfSix, singleBGLEPrice, remainingBGLE); + } + + public override string ToString() + { + if (Items.Count == 0) return "Basket is empty"; + + string result = "Basket contains:\n"; + foreach (var item in Items) + { + result += "- " + item + "\n"; + } + return result; + } +} \ No newline at end of file diff --git a/exercise.main/Filling.cs b/exercise.main/Filling.cs new file mode 100644 index 00000000..838819a3 --- /dev/null +++ b/exercise.main/Filling.cs @@ -0,0 +1,7 @@ +namespace exercise; + +public class Filling +{ + public string Name { get; set; } + public decimal Price { get; set; } +} \ No newline at end of file diff --git a/exercise.main/Item.cs b/exercise.main/Item.cs new file mode 100644 index 00000000..836ba42e --- /dev/null +++ b/exercise.main/Item.cs @@ -0,0 +1,22 @@ +namespace exercise; + +public class Item +{ + public string SKU { get; set; } + public decimal Price { get; set; } + public string Name { get; set; } + public string Variant { get; set; } + + public Item(string sku, decimal price, string name, string variant) + { + SKU = sku; + Price = price; + Name = name; + Variant = variant; + } + + public override string ToString() + { + return $" {SKU} {Name} {Price:C} {Variant}"; + } +} diff --git a/exercise.main/Program.cs b/exercise.main/Program.cs index 3751555c..fb6c4436 100644 --- a/exercise.main/Program.cs +++ b/exercise.main/Program.cs @@ -1,2 +1,3 @@ -// See https://aka.ms/new-console-template for more information -Console.WriteLine("Hello, World!"); +using exercise; + +Receipt receipt = new Receipt(); \ No newline at end of file diff --git a/exercise.main/Receipt.cs b/exercise.main/Receipt.cs new file mode 100644 index 00000000..f22bd2d0 --- /dev/null +++ b/exercise.main/Receipt.cs @@ -0,0 +1,22 @@ +namespace exercise; + +public class Receipt +{ + public Receipt() + { + Store store = new Store(); + Basket basket = new Basket(); + DateTime utcNow = DateTime.UtcNow; + + for (int i = 0; i < 8; i++) + { + basket.AddItem(store.AvailableItems[i]); + } + Console.WriteLine("~~~ Bobs Bagels ~~~"); + Console.WriteLine(utcNow); + Console.WriteLine("----------------"); + Console.WriteLine(basket); + Console.WriteLine("----------------"); + Console.WriteLine("Total " + basket.PriceInBasket() + " kr"); + } +} diff --git a/exercise.main/Store.cs b/exercise.main/Store.cs new file mode 100644 index 00000000..661077f4 --- /dev/null +++ b/exercise.main/Store.cs @@ -0,0 +1,37 @@ +namespace exercise; + +public class Store +{ + public List AvailableItems { get; private set; } + + public Store() + { + AvailableItems = CreateFakeItems(); + } + + private List CreateFakeItems() + { + return new List + { + // Bagels + new Item("BGLO", 0.49m, "Bagel", "Onion"), + new Item("BGLP", 0.39m, "Bagel", "Plain"), + new Item("BGLE", 0.49m, "Bagel", "Everything"), + new Item("BGLS", 0.49m, "Bagel", "Sesame"), + + // Coffee + new Item("COFB", 0.99m, "Coffee", "Black"), + new Item("COFW", 1.19m, "Coffee", "White"), + new Item("COFC", 1.29m, "Coffee", "Cappuccino"), + new Item("COFL", 1.29m, "Coffee", "Latte"), + + // Fillings + new Item("FILB", 0.12m, "Filling", "Bacon"), + new Item("FILE", 0.12m, "Filling", "Egg"), + new Item("FILC", 0.12m, "Filling", "Cheese"), + new Item("FILX", 0.12m, "Filling", "Cream Cheese"), + new Item("FILS", 0.12m, "Filling", "Smoked Salmon"), + new Item("FILH", 0.12m, "Filling", "Ham") + }; + } +} \ No newline at end of file diff --git a/exercise.main/domainModel.md b/exercise.main/domainModel.md new file mode 100644 index 00000000..9c467259 --- /dev/null +++ b/exercise.main/domainModel.md @@ -0,0 +1,17 @@ +| Class | Method/Property | Scenario | Output | + Basket AddItem(Store item) Add a bagel to the basket void + Basket RemoveItem(Store item) Remove a bagel from the basekt void + Basket IsBasketFull(Inventory inventory) Check if basket is full bool + Basket IsItemInBasket() Check if given item is in basket bool + Basket PriceInBasket() Give total price of items in basket decimal + + Store SetBasketSize(int i) Change the basket size int + Store PriceOfBagel(Store item) Return the price of the given bagel decimal + Store priceOfFilling(Filling filling) Returns the price for the selected filling decimal + Store addFilling(Store item) Add filling to bagel void + Store isInStock(Store item) Is selected item in stock bool + + + + + diff --git a/exercise.main/userStories.md b/exercise.main/userStories.md new file mode 100644 index 00000000..49fada52 --- /dev/null +++ b/exercise.main/userStories.md @@ -0,0 +1,59 @@ + +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. + + +2. +As a member of the public, +So I can change my order, +I'd like to remove a bagel from my basket. + + +3. +As a member of the public, +So that I can not overfill my small bagel basket +I'd like to know when my basket is full when I try adding an item beyond my basket capacity. + + +4. +As a Bob's Bagels manager, +So that I can expand my business, +I’d like to change the capacity of baskets. + + +5. +As a member of the public +So that I can maintain my sanity +I'd like to know if I try to remove an item that doesn't exist in my basket. + + +6. +As a customer, +So I know how much money I need, +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. + + +8. +As a customer, +So I can shake things up a bit, +I'd like to be able to choose fillings for my bagel. + + +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. + + +10. +As the manager, +So we don't get any weird requests, +I want customers to only be able to order things that we stock in our inventory. \ No newline at end of file