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
20 changes: 20 additions & 0 deletions domain-model.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Domain Model


| Classes | Methods/Properties | Scenario | Outputs |
|-----------------|----------------------------------------------------|------------------------------------------------------------------------------|-------------------------------------------
|Basket.cs |AddItem(Item item) |add a new item to the basket |the added item or null if basket full |
|Basket.cs |RemoveItem(Guid id) |remove an item from the basket |the removed item or null if not found |
|Basket.cs |ChangeBasketCapacity(int capacity) |change capacity of basket |true if success or false if invalid |
|Basket.cs |GetBasketTotalPrice() |get the summed cost of the bagels in the basket |float |
|Product.cs |GetPrice() |get the price of an item |float |
|Filling.cs |ChooseFillings(Fillings fillings) |select the fillings of a bagel |the selected fillings |
|Product.cs |ChangePrice(float nprice) |change the price of a product |the new price (float) |
|Coffee.cs |CalculatePrice() |set price of item depending on type |the price (float) |
|Bagel.cs |CalculatePrice() |set price of item depending on type |the price (float) |
|Filling.cs |CalculatePrice() |set price of item depending on type |the price (float) |
|PriceLookup.cs |LookupPriceByType(Enum) |look up the price of an item |the price (float) |
|Basket.cs |PrintReceipt() |print a receipt that shows all basket items, their price and total cost |the price (float) |
|ProductBundle.cs |BagelDeal6() |create a discount deal with 6 bagels |void |
|ProductBundle.cs |BagelDeal12() |create a discount deal with 12 bagels |void |
|ProductBundle.cs |CoffeeAndBagelDeal() |create a discount deal with a black coffee and bagel |void |
58 changes: 58 additions & 0 deletions exercise.main/Bagel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace exercise.main
{
public class Bagel : Product
{
private Filling _filling;
private ProductLookup _lookup = new();
private readonly BagelType _type;
public Bagel(Filling filling, BagelType type) : base(type)
{
_filling = filling;
_type = type;
this.CalculatePrice();
this.SKU = _lookup.LookupSKUByType(type);
}

public Bagel(BagelType type) : base(type)
{
_type = type;
this.CalculatePrice();
this.SKU = _lookup.LookupSKUByType(type);
_filling = new Filling(FillingType.None);
}

public Filling Filling { get => _filling; set { _filling = value; } }
public Filling ChooseFillings(Filling filling)
{
_filling = filling;

this.Price += _lookup.LookupPriceByType(filling.Type);

return _filling;
}

private float CalculatePrice()
{
if (_filling == null)
{
this.Price = _lookup.LookupPriceByType(_type);
}
else
{
this.Price = _lookup.LookupPriceByType(_type) + _filling.Price;
}
return this.Price;
}

public override string ToString()
{
return _type.ToString();
}
}
}
13 changes: 13 additions & 0 deletions exercise.main/BagelType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace exercise.main
{
public enum BagelType
{
Onion, Plain, Everything, Sesame
}
}
120 changes: 120 additions & 0 deletions exercise.main/Basket.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace exercise.main
{
public class Basket
{
private List<Product> _items;
private int _capacity;
private int _count;
private Role _role;

public Basket(List<Product> items, int capacity, Role role)
{
_items = items;
_capacity = capacity;
_role = role;
}
public Basket(int capacity, Role role)
{
_items = new List<Product>();
_capacity = capacity;
_role = role;
}
public Basket(int capacity)
{
_items = new List<Product>();
_capacity = capacity;
}
public int Capacity {get {return _capacity;} }
public int Count { get { return _count; } }

public Product? AddItem(Product item)
{
if (_count <= _capacity)
{
_items.Add(item);
_count++;
return item;
}
else return null;
}

public Product? RemoveItem(Guid id)
{
if (_count == 0) { return null; }

foreach (Product item in _items)
{
if (item.Id == id)
{
_items.Remove(item);
_count--;
return item;
}
}
return null;
}

public bool ChangeCapacity(int ncapacity)
{
if(_role == Role.Manager && ncapacity >= 0)
{
_capacity = ncapacity;
return true;
}
return false;
}

public float GetBasketTotalPrice()
{
if(_count <= 0) { return 0; }
float cost = _items.Sum(x => x.Price);
return cost;
}

public void PrintReceipt()
{
float total = GetBasketTotalPrice();
CultureInfo local = new("en-GB");

string text =
"=============[ Bob's Bagels Receipt ]===============\n" +
"====================================================\n\n";
foreach (Product item in _items)
{
if (item is ProductBundle) { text += $"{item.ToString()}\n\n"; continue; }
text += $"{item.ToString()} --- {item.Price.ToString("C", local)}\n\n";
}

text += $"\n\n\nTotal: {total.ToString("C", local)}\n====================================================";

Console.WriteLine(text);
}

public void SendSMSorderSummary()
{
float total = GetBasketTotalPrice();
CultureInfo local = new("en-GB");

string text =
"[ Bob's Bagels Order Summary]\n\n";
foreach (Product item in _items)
{
if (item is ProductBundle) { text += $"{item.ToString()}\n\n"; continue; }
text += $"{item.ToString()} --- {item.Price.ToString("C", local)}\n\n";
}

text += $"\n\n\nTotal: {total.ToString("C", local)}";


}


}
}
13 changes: 13 additions & 0 deletions exercise.main/BundleType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace exercise.main
{
public enum BundleType
{
bagel6, bagel12, coffeeBagel
}
}
31 changes: 31 additions & 0 deletions exercise.main/Coffee.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace exercise.main
{
public class Coffee : Product
{
private CoffeeType _type;
private readonly ProductLookup _lookup = new ProductLookup();
public Coffee(CoffeeType type) : base(type)
{
_type = type;
this.Price = CalculatePrice();
}

private float CalculatePrice()
{
this.Price = _lookup.LookupPriceByType(_type);
return this.Price;
}

public override string ToString()
{
return _type.ToString();
}
}

}
13 changes: 13 additions & 0 deletions exercise.main/CoffeeType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace exercise.main
{
public enum CoffeeType
{
Black, White, Capuccino, Latte
}
}
33 changes: 33 additions & 0 deletions exercise.main/Filling.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;

namespace exercise.main
{
public class Filling : Product
{
private FillingType _type;
private readonly ProductLookup _lookup = new();
public Filling(FillingType type) : base(type)
{
_type = type;
this.CalculatePrice();
}

private float CalculatePrice()
{
this.Price = _lookup.LookupPriceByType(_type);
return this.Price;
}

public override string ToString()
{
return $"{_type.ToString()}";
}


}
}
13 changes: 13 additions & 0 deletions exercise.main/FillingType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace exercise.main
{
public enum FillingType
{
Bacon, Egg, Cheese, Cream_Cheese, Smoked_Salmon, Ham, None
}
}
13 changes: 13 additions & 0 deletions exercise.main/ItemType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace exercise.main
{
public enum ItemType
{

}
}
43 changes: 43 additions & 0 deletions exercise.main/Product.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace exercise.main
{
public class Product
{
private Guid _id;
private float _price;
private Enum _type;
private string _SKU;

public Product(Enum type)
{
_id = Guid.NewGuid();
_price = 0;
_type = type;
_SKU = "";
}

public Guid Id { get { return _id; } set { _id = value; } }

public float Price { get { return _price; } set { _price = value; } }
public Enum Type { get { return _type; } set { _type = value; } }

public string SKU { get { return _SKU; } set { _SKU = value; } }

public float changePrice(float nprice)
{
if (nprice < 0)
{
_price = 0;
return 0;
}
_price = nprice;
return _price;
}

}
}
Loading