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

| Classes | Methods/Properties | Scenario | Outputs |
|-----------|-----------------------------------|---------------------------------------------|-------------------------|
| | AddToBasket(string Id) | Adds an order to basket | |
| | RemoveFromBasket(string Id) | Removes an order form basket | |
| Basket.cs | CheckFull() | Checks if basket is at max capacity | "Basket is full" |
| | SetBasketSize(int size) | Sets a new max capacity to baskets | |
| | RemoveFromBasket(string Id) | Tries to remove nonexsistent item | "No such item" |
| | GetTotal() | See the total cost of items in basket | Total cost |
| | Property to expose price of bagel | See price of bagel before adding to basket | Bagel cost |
| | AddFillig(string Id) | Adds filling to bagel | |
| | Property to expose price filling | See price of filling before adding to bagel | Filling cost |
| | AddToBasket(string Id) | Tries to add nonexsistent item | "No such ware in stock" |
90 changes: 90 additions & 0 deletions exercise.main/Bagel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection.Metadata.Ecma335;
using System.Text;
using System.Threading.Tasks;

namespace exercise.main
{
public class Bagel : Item
{

private List<Filling> fillings_list;

public List<Filling> Fillings_list { get { return fillings_list; } set { fillings_list = value; } }

public static List<Filling> StockItems = new List<Filling>()
{
new Filling("FILB", "Filling", "Bacon", 0.12),
new Filling("FILE", "Filling", "Egg", 0.12),
new Filling("FILC", "Filling", "Cheese", 0.12),
new Filling("FILX", "Filling", "Cream Cheese", 0.12),
new Filling("FILS", "Filling", "Smoked Salmon", 0.12),
new Filling("FILH", "Filling", "Ham", 0.12)
};

public struct Filling
{
public string Id { get; }
public string Variant { get; }
public string Name { get; }
public double Price { get; }

public Filling(string id, string variant, string name, double price)
{
Id = id;
Variant = variant;
Name = name;
Price = price;
}

public string getFillingToString()
{
return $"{Id}, {Name}, {Variant}, {Price}";
}
}

public Bagel(string id, string name, string variant, double price) : base(id, name, variant, price) { }

public Bagel(string id, string name, string variant, double price, List<Filling> fillings) : base(id, name, variant, price)
{
fillings_list = fillings;
}


public override List<Filling> getFillings()
{
return fillings_list;
}

public override void addFilling(string order)
{
var fillingOrder = StockItems.FirstOrDefault(x => x.Id == order);

if (fillingOrder.Id == null) { throw new Exception("Order not in stock"); }
else { fillings_list.Add(fillingOrder); }
}


public override void removeFilling(string order)
{
var fillingOrder = fillings_list.FirstOrDefault(x => x.Id == order);

if (fillingOrder.Id == null) { throw new Exception("No such item in basket"); }
else { fillings_list.Remove(fillingOrder); }
}


public override double getPrice()
{
if (fillings_list != null && fillings_list.Count > 0)
{
return base.Price + fillings_list.Sum(f => f.Price);
}
return base.Price;
}


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

namespace exercise.main
{
public class Basket
{
private static int maxSize;
private List<Item> items;

public static List<Item> StockItems = new List<Item>()
{
new Bagel("BGLO", "Bagel", "Onion", 0.49, new List<Bagel.Filling>()),
new Bagel("BGLP", "Bagel", "Plain", 0.39),
new Bagel("BGLE", "Bagel", "Everything", 0.49),
new Bagel("BGLS", "Bagel", "Sesame", 0.49),
new Coffee("COFB", "Coffee", "Black", 0.99),
new Coffee("COFW", "Coffee", "White", 1.19),
new Coffee("COFC", "Coffee", "Cappucino", 1.29),
new Coffee("COFL", "Coffee", "Latte", 1.29)
};


public int MaxSize { get { return maxSize; } set { maxSize = value; } }

public List<Item> Items { get { return items; } set { items = value; } }


//public void addToBasket(Item order)
//{
// if (checkFull()){ throw new Exception("Basket is full"); }
// else if (!StockItems.Contains(order)) { throw new Exception("Order not in stock"); }
// else { items.Add(order); }
//}

public void addToBasket(string order)
{
var item = StockItems.FirstOrDefault(i => i.Id == order);

if (items.Count >= maxSize) { throw new Exception("Basket is full"); }
else if (item == null) { throw new Exception("Order not in stock"); }
else { items.Add(item); }
}


public void removeFromBasket(string order)
{
var item = items.FirstOrDefault(i => i.Id == order);

if (item == null) { throw new Exception("No such item in basket"); }
else { items.Remove(item); }
}

public void setBasketSize(bool manager, int newSize)
{
if (!manager) { throw new Exception("No persmission to alter size"); }
else { maxSize = newSize; }
}

public double getTotalCost()
{
if(items != null && items.Count > 0)
{
return Math.Round(items.Sum(i => i.getPrice()), 2);
}
return 0;
}

}
}
33 changes: 33 additions & 0 deletions exercise.main/Coffee.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.Text;
using System.Threading.Tasks;
using static exercise.main.Bagel;

namespace exercise.main
{
public class Coffee : Item
{
public Coffee(string id, string name, string variant, double price) : base(id, name, variant, price) { }

public override double getPrice()
{
return base.Price;
}

public override void addFilling(string order)
{
throw new Exception("Currently no filling for coffee");
}
public override void removeFilling(string order)
{
throw new Exception("Currently no filling for coffee");
}

public override List<Filling> getFillings()
{
throw new Exception("Currently no filling for coffee");
}
}
}
39 changes: 39 additions & 0 deletions exercise.main/Item.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static exercise.main.Bagel;

namespace exercise.main
{
public abstract class Item
{
public string Id { get; set; }
public string Name { get; set; }
public double Price { get; set; }
public string Variant { get; set; }

public Item(string id, string name, string variant, double price)
{
Id = id;
Name = name;
Variant = variant;
Price = price;

}

public abstract double getPrice();
public abstract void addFilling(string order);
public abstract void removeFilling(string order);
public abstract List<Filling> getFillings();

public string getItemToString()
{
return $"{Id}, {Name}, {Variant}, {Price}";
}
}



}
Loading