Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Done Core and all extensions #81

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
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
91 changes: 91 additions & 0 deletions DomainModel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@

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.



| Classes | Methods | Scenario | Outputs |
|-----------------|---------------------------------------------|------------------------------------|--------------------------------------------------|
| `Basket ` | `AddItem(Item item) ` | Add item to basket, if not full |(bool) True if added, otherwise false |
| | | | |
|-----------------|---------------------------------------------|------------------------------------|--------------------------------------------------|
| `Basket ` | `RemoveItem(Item item) ` | Remove item from basket, if exists |(bool) True if removed, otherwise false |
| | | | |
|-----------------|---------------------------------------------|------------------------------------|--------------------------------------------------|
| `Basket ` | `ChangeCapacity(Person person, int cap) ` | If manager, change capacity |(bool) Returns true if changed, false if not |
| | | | |
|-----------------|---------------------------------------------|------------------------------------|--------------------------------------------------|
| `Basket ` | `GetPrice() ` | returns price of basket |(double) Cost of basket |
| | | | |
|-----------------|---------------------------------------------|------------------------------------|--------------------------------------------------|
| `Basket ` | `GetDiscountPrice() ` | returns price of discount |(double) Cost of discount |
| | | | |
|-----------------|---------------------------------------------|------------------------------------|--------------------------------------------------|
| `Bagel ` | `AddFilling(string namefilling) ` | add filling to bagel |(string) returns string indicating if it was added|
| | | | |
|-----------------|---------------------------------------------|------------------------------------|--------------------------------------------------|
| `Bagel ` | `RemoveFilling(string nameFilling) ` | Removes filling from bagel |(bool) True if removed, otherwise false |
| | | | |
|-----------------|---------------------------------------------|------------------------------------|--------------------------------------------------|
| `Bagel ` | `GetPrice() ` | Gets price with fillings |(double) returns price of bagel |
| | | | |
|-----------------|---------------------------------------------|------------------------------------|--------------------------------------------------|
| `Receipt ` | `GetReceipt(Basket basket) ` | Gets receipt of basket |(string) returns receipt |
| | | | |
|-----------------|---------------------------------------------|------------------------------------|--------------------------------------------------|
| `Receipt ` | `PrintReceipt() ` | Prints receipt |(void) prints receipt |
| | | | |
|-----------------|---------------------------------------------|------------------------------------|--------------------------------------------------|
| `SMSService ` | `SendSMS(string message) ` | Sends receipt of order |(void) Sends receipt by SMS |
| | | | |
|-----------------|---------------------------------------------|------------------------------------|--------------------------------------------------|
| `Inventory ` | `GetInventory() ` | Method for checking avaliable stock|(List<Item>) returns list with stock of items |
| | | | |
|-----------------|---------------------------------------------|------------------------------------|--------------------------------------------------|
100 changes: 100 additions & 0 deletions exercise.main/Bagel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace exercise.main
{
public class Bagel : Item
{

private int _id;
public int Id
{
get { return _id; }
set { _id = value; }
}
private string _sku;
public string Sku
{
get { return _sku; }
set { _sku = value; }
}
private string _name;
public string Name
{
get => _name; set => _name = value;
}
private double _price;
public double Price
{
get => _price; set => _price = value;
}
private string _variant;
public string Variant
{
get => _variant; set => _variant = value;
}

private List<Filling> _fillings;
public List<Filling> Fillings
{
get => _fillings; set => _fillings = value;
}

public Bagel(string sku, double price, string variant, string name)
{
this._sku = sku;
this._name = name;
this._price = price;
this._variant = variant;
this._fillings = new List<Filling>();
}


public List<Filling> GetFillings()
{
return this._fillings;
}
public string AddFilling(string nameFilling)
{
List<Item> inventory = Inventory.GetInventory();

foreach (var item in inventory)
{
if (item.Name.Equals(nameFilling))
{
Filling filling = (Filling)item;
_fillings.Add(filling);
return "Filling added";
}
}
return "Filling not in inventory";
}

public bool RemoveFilling(string filling1)
{
foreach (var item in _fillings)
{
if (item.Name.Equals(filling1))
{
_fillings.Remove(item);
return true;
}
}
return false;
}

public double GetPrice()
{
double price = this._price;

foreach (var item in _fillings)
{
price += item.Price;
}
return price;
}
}
}
126 changes: 126 additions & 0 deletions exercise.main/Basket.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.AccessControl;
using System.Text;
using System.Threading.Tasks;

namespace exercise.main
{
public class Basket
{
private int _id;
private int _capacity;
public int Capacity { get { return _capacity; }set { _capacity = value; } }

private List<Item> _items;

public List<Item> Items
{
get { return _items; }

}


public Basket(int capacity) {
this._items = new List<Item>();
this._capacity = capacity;
}

public bool AddItem(Item item)
{

if (_items.Count >= _capacity){
return false;
}
_items.Add(item);
return true;
}

public bool RemoveItem(Item item)
{

if (_items.Contains(item))
{
_items.Remove(item);
return true;
}
return false;
}

public double GetPrice()
{
double price = 0;

foreach(var product in _items)
{
price += product.Price;

}
price = Math.Round(price, 2);


return price;
}

public double GetDiscountPrice()
{

List<Item> bagels = this._items.Where(x => x.GetType() == typeof(Bagel)).ToList();
List<Item> coffee = this._items.Where(x => x.GetType() == typeof(Coffee)).ToList();
List<Item> filling = this._items.Where(x => x.GetType() == typeof(Filling)).ToList();
List<Filling> bagelFilling = new List<Filling>();


foreach (var item in bagels)
{
Bagel bagel = (Bagel)item;

bagelFilling.AddRange(bagel.GetFillings());
}
//Getting discount on bagels
double price = 0;
int bagelsLeft = bagels.Count;

price += (bagelsLeft / 12) * 3.99;
bagelsLeft = bagels.Count % 12;
price += (bagelsLeft / 6) * 2.49;
bagelsLeft = bagelsLeft % 6;

price += bagelsLeft * 0.49;

//Adding fillings to price

foreach (var item in bagelFilling)
{
price += item.Price;
}

//Adding price of coffee items
foreach (var item in coffee)
{
price += item.Price;
}

//Adding price of fillings
foreach (var item in filling)
{
price += item.Price;
}
return Math.Round(price, 2);

}

public bool ChangeCapacity(Person person, int newCapacity)
{
if (person.Manager == true)
{
_capacity = newCapacity;
return true;
}
return false;
}


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

namespace exercise.main
{
public static class BobsBagel
{

public static string Name { get; set; } = "Bob's Bagels";


}
}
Loading