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
Binary file added BobsBagel.drawio (1).png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,20 @@ So we don't get any weird requests,
I want customers to only be able to order things that we stock in our inventory.
```


```
11.
As a customer,
So I don't over-spend,
I'd like to get discount when I buy more than 6 bagels.
```

```
11.
As a customer,
So I can see what each of the items costs,
I'd like to get a receipt.
```
## Bob's Inventory

| SKU | Price | Name | Variant |
Expand Down
86 changes: 86 additions & 0 deletions domain-model.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
| Classes | Methods/Properties | Scenario | Outputs |
|---------------|---------------------------------------------------|-------------------------------------------------------|---------------|
|Basket |Add(Bagel bagel) | add Bagel | bool |
|Basket |Remove(Bagel bagel) | Remove Bagel | bool |
|Basket |IsFull() | See if basket is full | bool |
|Basket |ChangeCapacity(int capacity) | Change capacity | bool |
|Basket |RemoveExist(Bagel bagel) | try to remove an item that doesn't exist in my basket | bool |
|Basket |TotalCost() | Check total cost of items in my basket | double |
|Basket |PriceBagel(Bagel bagel) | Check cost of a bagel | double |
|Bagel |Choosefillings() | choose fillings for my bagel | List<Fillings>|
|Basket |PriceFilling(Filling filling) | Check cost of each filling | double |
|Basket |OrderInventory() | order things that we stock in our inventory. | bool |





```
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.
```
181 changes: 181 additions & 0 deletions exercise.main/Basket.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
using exercise.main.Product;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Reflection.Metadata.Ecma335;
using System.Security.Principal;
using System.Text;
using System.Threading.Tasks;

namespace exercise.main
{
public class Basket
{
private int _ID = 0;
private int _capacity = 30;
private List<IProduct> _items = new List<IProduct>();

private List<Bagel> Amout_bagels()
{
List<Bagel> bagels = new List<Bagel>();
foreach (IProduct item in _items)
{
if (item is Bagel bagel)
{
bagels.Add(bagel);
}
}
return bagels;
}

private List<Coffee> Amout_Coffee()
{
List<Coffee> coffee = new List<Coffee>();
foreach (IProduct item in _items)
{
if (item is Coffee c)
{
if (c.SKU == "COFB")
{
coffee.Add(c);
}
}
}
return coffee;
}

public bool Add(IProduct item)
{
if (_capacity > 0)
{
_items.Add(item);
_capacity--;
item.ID = _ID;
_ID++;
return true;
}
return false;
}

public void Remove(int id)
{
_items.RemoveAll(x => x.ID == id);
_capacity++;
}

//public bool ValidSixBagels()
//{

// if (_items.Where(p => p.SKU == "BGLO"))
// {
// return true;
// }
// if (_items.Any(p => p.SKU == "BGLP"))
// {
// return true;
// }
// return false;
//}

public double Discount()
{
// All bagels cost the same
double total = 0;
double coffeeDiscount = 0;
List<Bagel> bagels = Amout_bagels();
List<Coffee> coffees = Amout_Coffee();

Console.WriteLine("Amout of Bagel: " + bagels.Count);
int BigPackBagels = 0;
int SmallPackBagels = 0;

int rest = 0;

if (bagels.Count >= 6)
{
// For Big pack 12 for 3.99
BigPackBagels += bagels.Count / 12;

// For Small pack 6 for 2.49
SmallPackBagels += (bagels.Count - (BigPackBagels * 12)) / 6;
rest += (bagels.Count - (SmallPackBagels * 6)) % 6;

}

// Add coffee and Bagel Discount
int amout_coffeeDiscount = 0;
int max = 0;
int coffee = coffees.Count;
if (coffee > rest) // Maybe get this on one-line
{
max = coffee;
}
else
{
max = rest;
}

for (int i = 0; i < max; i++)
{
if (coffee > 0 & rest > 0)
{
coffee--;
rest--;
amout_coffeeDiscount++;
}
}

total += amout_coffeeDiscount * 1.25 + coffeeDiscount + (rest * 0.49) + (coffee * 0.99) + (BigPackBagels * 3.99) + (SmallPackBagels * 2.49);

return total;
}

public string printReceipt()
{

StringBuilder sb = new StringBuilder();
sb.Append($"~~~Bob's Bagels ~~~");
sb.Append($"\n{DateTime.Now.ToString()}");

sb.Append($"\n----------------------------");



foreach (IProduct item in _items)
{
sb.Append($"\n{item.Name} - £{item.Price}");
}
sb.Append($"\n----------------------------");
sb.Append($"\nTotal : {this.TotalCost()}");
sb.Append($"\nThank you for your order!");

return sb.ToString();
}

// ~~~Bob's Bagels ~~~

// 2021-03-16 21:38:44

//----------------------------

//Onion Bagel 2 £0.98
//Plain Bagel 12 £3.99
//Everything Bagel 6 £2.49
//Coffee 3 £2.97

//----------------------------
//Total £10.43

// Thank you
// for your order!

public bool IsFull() { return _capacity <= 0; }

public double TotalCost() { return _items.Sum(product => product.Price); }

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

public int Capacity { get { return _capacity; } set { _capacity = value; } }
}
}
77 changes: 77 additions & 0 deletions exercise.main/Inventory.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
using exercise.main.Product;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace exercise.main
{
public class Inventory
{
// Bagel
public Bagel getOnionBagel()
{
return new Bagel() { SKU = "BGLO", Name = "Onion", BagelPrice = 0.49};
}
public Bagel getPlainBagel()
{
return new Bagel() { SKU = "BGLP", Name = "Plain", BagelPrice = 0.39 };
}
public Bagel getEverythingBagel()
{
return new Bagel() { SKU = "BGLE", Name = "Everything", BagelPrice = 0.49 };
}
public Bagel getSesameBagel()
{
return new Bagel() { SKU = "BGLS", Name = "Sesame", BagelPrice = 0.49 };
}

//Coffee
public Coffee getBlackCoffee()
{
return new Coffee() { SKU = "COFB", Name = "Black", Price = 0.99 };
}
public Coffee getWhiteCoffee()
{
return new Coffee() { SKU = "COFW", Name = "White", Price = 1.19 };
}
public Coffee getCapuccinoCoffee()
{
return new Coffee() { SKU = "COFC", Name = "Capuccino", Price = 1.19 };
}
public Coffee getLatteCoffee()
{
return new Coffee() { SKU = "COFL", Name = "Latte", Price = 0.99 };
}

//Filling
public Filling GetBaconFilling()
{
return new Filling() { SKU = "FILB", Name = "Bacon", Price = 0.12 };
}
public Filling GetEggFilling()
{
return new Filling() { SKU = "FILE", Name = "Egg", Price = 0.12 };
}
public Filling GetCheeseFilling()
{
return new Filling() { SKU = "FILC", Name = "Cheese", Price = 0.12 };
}
public Filling GetCCFilling()
{
return new Filling() { SKU = "FILX", Name = "Cream Cheese", Price = 0.12 };
}
public Filling GetSSFilling()
{
return new Filling() { SKU = "FILS", Name = "Smoked Salmon", Price = 0.12 };
}
public Filling GetHamFilling()
{
return new Filling() { SKU = "FILH", Name = "Ham", Price = 0.12 };
}


}
}
Loading