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
22 changes: 22 additions & 0 deletions DomainModel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Core Requirements

| Classes | Methods/Properties | Scenario | Outputs
| ----------- | ------------------------------------------------------ | --------------------------------------- | ---------------------------------
| Product.cs | string SKU | Short code for name + variant | String with SKU code
| Product.cs | float Price | Pricing for each item | float with price in decimal
| Product.cs | enum Name | Product type for each item to get | Bagel, Coffee, Filling
| Product.cs | enum BagelVariant | Types of variant you can get with bagel | Onion, Plain, Everything, Sesame
| Product.cs | enum CoffeeVariant | Types of variant you can get with Coffee| Black, White, Cappucino, Latte
| Product.cs | enum FillingVariant | Types of variant you can get for Filling| Bacon, Egg, Cheese, CreamCheese, SmokedSalmon, Ham
| Basket.cs | List<\ProductList\> Basket | List to add each chosen item to | Task added to list
| Basket.cs | Guid id | Id to keep track of items in basket | Id for each item
| Basket.cs | bool IsFull | Bool to check to see if basket is full | True or False
| Basket.cs | int Capacity | Int to decide max amount of items | Int that dictates max items
| Basket.cs | AddItem(Product prodcut) | Add item to the basket list | Product added to list
| Basket.cs | RemoveItem(Guid itemId) | Remove specific item from basket | Specific item removed from list
| Basket.cs | ChangeCapacity(int Capacity) | Changes the total capacity of the basket| A changed version of the Capacity
| Checkout.cs | int TotalPrice | Int tracking the total price all items | Int in $$$
| Checkout.cs | string Receipt | Clear version of all total costs written| Each item and it's costs written in console
| Checkout.cs | int Discount | Discount if enough items are bought | New price calculated with new discount
| Checkout.cs | string OrderConfirmation | Using twilio to print a conformation | SMS with order conformation
| Checkout.cs | CashOrCard() | Delivers the user their total | A console log with an overview of the transactions
48 changes: 48 additions & 0 deletions exercise.main/Basket.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace exercise.main
{
public class Basket
{
public List<Product> Products { get; set; }
public int Capacity { get; set; }

public Basket(int capacity)
{
Capacity = capacity;
Products = new List<Product>();
}

public bool AddItem(Product product)
{
if (Products.Count >= Capacity)
{
return false;
}

Products.Add(product);
return true;
}

public bool RemoveItem(Product product)
{
var selectedItem = Products.FirstOrDefault(p => p.Id == product.Id);
if (selectedItem == null)
{
return false;
}

Products.Remove(selectedItem);
return true;
}

public void ChangeCapacity(int capacity)
{
Capacity = capacity;
}
}
}
86 changes: 86 additions & 0 deletions exercise.main/CheckOut.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace exercise.main
{
public class CheckOut
{
public float TotalPrice(Basket basket)
{
var groupedBySKU = basket.Products.GroupBy(p => p.SKU);

float total = 0;

foreach (var group in groupedBySKU)
{
string sku = group.Key;
int amount = group.Count();
float price = group.First().Price;

if (Inventory.Discounts.ContainsKey(sku))
{
var special = Inventory.Discounts[sku];
int n = special.RequiredAmount;
float discountPrice = special.DiscountPrice;

int sets = amount / n;
int remainder = amount % n;

total += (sets * discountPrice) + (remainder * price);
}
else
{
total += amount * price;
}


}

return total;
}

public string Receipt(Basket basket)
{

var receipt = new StringBuilder();
receipt.AppendLine("\n~~~ Bob's Bagels ~~~\n");
receipt.AppendLine(DateTime.Now.ToString() + "\n");
receipt.AppendLine("----------------------------\n");

var groupedBySKU = basket.Products.GroupBy(p => p.SKU);

foreach (var group in groupedBySKU)
{
string sku = group.Key;
int amount = group.Count();
string itemName = group.First().Name.ToString();
string variant = group.First().Variant.ToString();
float price = group.First().Price;

float total = 0;

if (Inventory.Discounts.ContainsKey(sku))
{
var special = Inventory.Discounts[sku];
total = special.CalculateDiscount(amount, price);
}
else
{
total = amount * price;
}

receipt.AppendLine($"{variant} {itemName} {amount} ${total:0.00}");
}

receipt.AppendLine("----------------------------\n");
receipt.AppendLine($"Total: ${TotalPrice(basket):0.00}\n");
receipt.AppendLine(" Thank you ");
receipt.AppendLine(" for your order ");

return receipt.ToString();
}
}
}
28 changes: 28 additions & 0 deletions exercise.main/Discount.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace exercise.main
{
public class Discount
{
public int RequiredAmount { get; set; }
public float DiscountPrice { get; set; }

public Discount(int requiredAmount, float discountPrice)
{
RequiredAmount = requiredAmount;
DiscountPrice = discountPrice;
}

public float CalculateDiscount(int amount, float price)
{
int basketAmount = amount / RequiredAmount;
int remainder = amount % RequiredAmount;

return (basketAmount * DiscountPrice) + (remainder * price);
}
}
}
74 changes: 74 additions & 0 deletions exercise.main/Inventory.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace exercise.main
{
public static class Inventory
{
public static Dictionary<BagelVariant, float> Bagels = new Dictionary<BagelVariant, float>()
{
{ BagelVariant.Onion, 0.49f },
{ BagelVariant.Plain, 0.39f },
{ BagelVariant.Everything, 0.49f },
{ BagelVariant.Sesame, 0.49f }
};

public static Dictionary<CoffeeVariant, float> Coffees = new Dictionary<CoffeeVariant, float>()
{
{ CoffeeVariant.Black, 0.99f },
{ CoffeeVariant.White, 1.19f },
{ CoffeeVariant.Cappucino, 1.29f },
{ CoffeeVariant.Latte, 1.29f }
};

public static Dictionary<FillingVariant, float> Fillings = new Dictionary<FillingVariant, float>()
{
{ FillingVariant.Bacon, 0.12f },
{ FillingVariant.Egg, 0.12f },
{ FillingVariant.Cheese, 0.12f },
{ FillingVariant.CreamCheese, 0.12f },
{ FillingVariant.SmokedSalmon, 0.12f },
{ FillingVariant.Ham, 0.12f }
};

public static Dictionary<string, Discount> Discounts = new Dictionary<string, Discount>()
{
{ "BGLO", new Discount(6, 2.49f) },
{ "BGLP", new Discount(12, 3.99f) },
{ "BGLE", new Discount(6, 2.49f) }
};

public static Product CreateBagel(BagelVariant variant)
{
if (!Bagels.ContainsKey(variant))
{
throw new InvalidOperationException("Bagel not in inventory");
}

return new Product(ProductName.Bagel, variant, Bagels[variant]);
}

public static Product CreateCoffee(CoffeeVariant variant)
{
if (!Coffees.ContainsKey(variant))
{
throw new InvalidOperationException("Coffee not in inventory");
}

return new Product(ProductName.Coffee, variant, Coffees[variant]);
}

public static Product CreateFilling(FillingVariant variant)
{
if (!Fillings.ContainsKey(variant))
{
throw new InvalidOperationException("Filling not in inventory");
}

return new Product(ProductName.Filling, variant, Fillings[variant]);
}
}
}
60 changes: 60 additions & 0 deletions exercise.main/Product.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace exercise.main
{

public enum ProductName
{
Bagel, Coffee, Filling
}

public enum BagelVariant
{
Onion, Plain, Everything, Sesame
}

public enum CoffeeVariant
{
Black, White, Cappucino, Latte
}

public enum FillingVariant
{
Bacon, Egg, Cheese, CreamCheese, SmokedSalmon, Ham
}

public class Product
{
public string SKU { get; set; }
public float Price { get; set; }
public ProductName Name { get; set; }
public Enum Variant { get; set; }
public Guid Id { get; set; }

public Product(ProductName name, Enum variant, float price)
{
Name = name;
Variant = variant;
Price = price;
SKU = CreateSKU();
Id = Guid.NewGuid();
}

private string CreateSKU()
{
string nameCode = Name switch
{
ProductName.Bagel => "BGL",
ProductName.Coffee => "COF",
ProductName.Filling => "FIL"
};

return nameCode + Variant.ToString().Substring(0, 1).ToUpper();
}

}
}
Loading