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

Ingeborg Brommeland Austeid #69

Open
wants to merge 31 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
78e8578
adds unfinished domain model
Ingeborgausteid Aug 16, 2024
d3797c9
adds updated domain model
Ingeborgausteid Aug 19, 2024
f59b421
adds classes Basket, InventoryItem and BobsInventory
Ingeborgausteid Aug 19, 2024
663f985
adds initial test setup
Ingeborgausteid Aug 19, 2024
6c5ad33
adds source code to pass 'AddItemToBasketTest'
Ingeborgausteid Aug 19, 2024
c04c50e
adds failing 'RemoveItemFromBasketTest'
Ingeborgausteid Aug 19, 2024
1909144
adds source code to pass 'RemoveItemFromBasketTest'
Ingeborgausteid Aug 19, 2024
42147ac
adds source code to pass 'BasketIsFullTest'
Ingeborgausteid Aug 19, 2024
34849d7
adds failing 'CanChangeCapacityTest'
Ingeborgausteid Aug 19, 2024
2519c17
adds source code to pass 'CanChangeCapacityTest'
Ingeborgausteid Aug 19, 2024
31b51f6
adds 'ItemIsNOtInBasketTest' with source code to pass
Ingeborgausteid Aug 19, 2024
e9753a4
adds failing 'TotalCostofBasketTest'
Ingeborgausteid Aug 19, 2024
896a2cc
adds source code to pass 'TotalCostofBasketTest'
Ingeborgausteid Aug 19, 2024
9054b8c
adds failing 'GetCostofItemTest'
Ingeborgausteid Aug 20, 2024
f8ef028
adds source code to pass 'GetCostofItemTest'
Ingeborgausteid Aug 20, 2024
f9c0e23
adds source code to pass 'CanOnlyOrderFromInventoryTest'
Ingeborgausteid Aug 20, 2024
6aa21ab
adds updated domain model
Ingeborgausteid Aug 20, 2024
de503fb
adds updated domain model and user story for extension2 Receipts
Ingeborgausteid Aug 20, 2024
04d5a54
adds failing 'PrintReceiptTest'
Ingeborgausteid Aug 20, 2024
4266b40
adds source code to pass 'PrintReceiptTest'
Ingeborgausteid Aug 20, 2024
69fa02e
adds modified AddToReceipt method
Ingeborgausteid Aug 20, 2024
2234c08
adds updated domain model
Ingeborgausteid Aug 20, 2024
d65b3ea
adds updated domain model and user story for extension1 Discount
Ingeborgausteid Aug 21, 2024
377140e
adds test set up for extension 1
Ingeborgausteid Aug 21, 2024
bfdaf50
adds source code to pass 'Get6BagelDiscountTest'
Ingeborgausteid Aug 21, 2024
63e66d0
adds failing 'Get12BagelDiscountTest'
Ingeborgausteid Aug 21, 2024
01d210d
adds source code to pass 'Get12BagelDiscountTest'
Ingeborgausteid Aug 21, 2024
f877707
adds failing 'GetCoffeeAndBagelDiscountTest'
Ingeborgausteid Aug 21, 2024
bb0d9a9
adds source code to pass 'GetCoffeeAndBagelDiscountTest'
Ingeborgausteid Aug 21, 2024
651d05a
adds failing 'GetAllDiscountsTest'
Ingeborgausteid Aug 21, 2024
6aaeeaf
adds source code to pass 'GetAllDiscountsTest' and updated domain model
Ingeborgausteid Aug 22, 2024
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
177 changes: 177 additions & 0 deletions exercise.main/Basket.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
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 List<InventoryItem> _Basket = new List<InventoryItem>();

private BobsInventory BobsInventory = new BobsInventory();

private StringBuilder _receipt = new StringBuilder();

private int _capacity = 5;

private string _variant;

private int BagelCount;

private int CoffeeCount;



private StringBuilder AddToReceipt()
{
_receipt.AppendLine("~~~ Bob's Bagels ~~~");
_receipt.AppendLine();
_receipt.AppendLine(DateTime.Now.ToString());
_receipt.AppendLine();
_receipt.AppendLine("--------------------------");
_receipt.AppendLine();

int amount = 0;

foreach (var item in _Basket.Distinct())
{
amount = _Basket.Where(x => x.Variant == item.Variant).Count();
_receipt.AppendLine($"{item.Variant} {item.Name}\t{amount} £ {amount * item.Price}");

}

_receipt.AppendLine();
_receipt.AppendLine("--------------------------");

_receipt.AppendLine($"Total £ {TotalCost}");
_receipt.AppendLine();
_receipt.AppendLine();
_receipt.AppendLine("Thank you for your order!");


return _receipt;

}


private double GetSpecialOffer()
{

List<InventoryItem> tempBasket = new List<InventoryItem>();
tempBasket.AddRange(_Basket);

double totalwithDiscount = 0;


foreach (var item in tempBasket)
{
BagelCount = tempBasket.Where(item => item.Name == "Bagel").Count();
CoffeeCount = tempBasket.Where(item => item.Name == "Coffee").Count();
}


while (BagelCount >= 12)
{
totalwithDiscount += BobsInventory.TwelveBagelDiscount;

for(int i = 0; i < 12; i++)
{
InventoryItem removeBagel = tempBasket.First(item => item.Name == "Bagel");
tempBasket.Remove(removeBagel);
}

BagelCount -= 12;

}

while (BagelCount >= 6)
{
totalwithDiscount += BobsInventory.SixBagelDiscount;

for (int i = 0; i < 6; i++)
{
InventoryItem removeBagel = tempBasket.First(item => item.Name == "Bagel");
tempBasket.Remove(removeBagel);
}

BagelCount -= 6;

}

while(BagelCount >= 1 && CoffeeCount >= 1)
{

totalwithDiscount += BobsInventory.CoffeeAndBagel;

InventoryItem removeBagel = tempBasket.First(item => item.Name == "Bagel");
InventoryItem removeCoffee = tempBasket.First(item => item.Name == "Coffee");
tempBasket.Remove(removeBagel);
tempBasket.Remove(removeCoffee);
BagelCount --;
CoffeeCount --;

}

return totalwithDiscount + tempBasket.Sum(item => item.Price);
}


public bool AddItem(string variant)
{
_variant = variant;

if (!IsInInventory)
{
return false;
}

if (!IsBasketFull && IsInInventory)
{
_Basket.Add(BobsInventory._Bobsinventory.First(item => item.Variant == variant));
return true;
}
return false;

}

public bool RemoveItem(string variant)
{
_variant = variant;

if (IsInBasket)
{
_Basket.Remove(_Basket.First(item => item.Variant == variant));
return true;
}
return false;
}

public bool ChangeCapacity(int capacity, bool isManager)
{
if (isManager)
{
_capacity = capacity;
return true;
}
return false;
}


public int BasketCapacity { get { return _capacity; } set { _capacity = value; } }

public bool IsBasketFull { get { return _Basket.Count >= BasketCapacity ? true : false; } }

public bool IsInBasket { get { return _Basket.Any(item => item.Variant == _variant); } }

public bool IsInInventory { get { return BobsInventory._Bobsinventory.Any(item => item.Variant == _variant); } }

public double TotalCost { get { return _Basket.Sum(item => item.Price); } }

public string PrintReceipt { get { return AddToReceipt().ToString(); } }

public double TotalCostWithDiscount { get { return GetSpecialOffer(); } }
}
}
49 changes: 49 additions & 0 deletions exercise.main/BobsInventory.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
using Microsoft.VisualBasic;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace exercise.main
{
public class BobsInventory
{
private List<InventoryItem> inventory = new List<InventoryItem>();
private string _itemVariant;
private double _6BagelDiscount = 2.49;
private double _12BagelDiscount = 3.99;
private double _coffeeAndBagel = 1.25;

public BobsInventory()
{
inventory.Add(new InventoryItem("BGLO", 0.49, "Bagel", "Onion"));
inventory.Add(new InventoryItem("BGLP", 0.39, "Bagel", "Plain"));
inventory.Add(new InventoryItem("BGLE", 0.49, "Bagel", "Everything"));
inventory.Add(new InventoryItem("BGLS", 0.49, "Bagel", "Sesame"));


inventory.Add(new InventoryItem("COFB", 0.99, "Coffee", "Black"));
inventory.Add(new InventoryItem("COFW", 1.19, "Coffee", "White"));
inventory.Add(new InventoryItem("COFC", 1.29, "Coffee", "Capuccino"));
inventory.Add(new InventoryItem("COFL", 1.29, "Coffee", "Latte"));

inventory.Add(new InventoryItem("FILB", 0.12, "Filling", "Bacon"));
inventory.Add(new InventoryItem("FILE", 0.12, "Filling", "Egg"));
inventory.Add(new InventoryItem("FILC", 0.12, "Filling", "Cheese"));
inventory.Add(new InventoryItem("FILX", 0.12, "Filling", "Cream Cheese"));
inventory.Add(new InventoryItem("FILS", 0.12, "Filling", "Smoked Salmon"));
inventory.Add(new InventoryItem("FILH", 0.12, "Filling", "Ham"));

}

public List<InventoryItem> _Bobsinventory { get { return inventory; } }
public string ItemVariant { get { return _itemVariant; } set { _itemVariant = value; } }
public double GetCostofItem { get { return _Bobsinventory.First(item => item.Variant == ItemVariant).Price ; } }

public double SixBagelDiscount { get { return _6BagelDiscount; } }
public double TwelveBagelDiscount { get { return _12BagelDiscount; } }
public double CoffeeAndBagel { get { return _coffeeAndBagel; } }

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

namespace exercise.main
{
public class InventoryItem
{

public InventoryItem(string sku, double price, string name, string variant)
{
SKU = sku;
Price = price;
Name = name;
Variant = variant;

}

public string SKU { get; set; }

public double Price { get; set; }

public string Name { get; set; }

public string Variant { get; set; }

}
}
18 changes: 16 additions & 2 deletions exercise.main/Program.cs
Original file line number Diff line number Diff line change
@@ -1,2 +1,16 @@
// See https://aka.ms/new-console-template for more information
Console.WriteLine("Hello, World!");

using exercise.main;

Basket basket = new Basket();
basket.AddItem("Onion");
basket.AddItem("Onion");
basket.AddItem("Black");


string printedReceipt = basket.PrintReceipt;
Console.WriteLine(printedReceipt);



// See https://aka.ms/new-console-template for more information
//Console.WriteLine("Hello, World!");
86 changes: 86 additions & 0 deletions exercise.main/domain-model.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
User Stories
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 Bagel 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 a manager, So we don't get any weird requests, I want customer to only be able to order things that we stock in our inventory.

Extension2 Receipt
11. As a customer, So that I can track my spendings, I'd like to receive a receipt of my order.

Extension1 Discount
12. As a manager, So that I can provide my customers with some special offers, I want our inventory to include multi-priced items.
13. As a customer, So that I can save some money, I'd like to be able to receive discounts.


| Classes | Members | Methods | Scenario | Output
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
| InventoryItem | string SKU { get; set; } | | property to set SKU |
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
| InventoryItem | double Price { get; set; } | | property to set Price |
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
| InventoryItem | string Name { get; set; } | | property to set Name |
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
| InventoryItem | string Variant { get; set; } | | property to set Variant |
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
| InventoryItem | | InventoryItem(string sku, double price, string name, string variant) | constructor | InventoryItem
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

| BobsInventory | List<InventoryItem> BobsInventory | | list of available inventory items |
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
| BobsInventory | | BobsInventory() | constructor | BobsInventory
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
| BobsInventory | double GetCostofItem { get; set; } | | property to get cost of item | double
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
| BobsInventory | string ItemVariant { get; set; } | | property to set variant of item | string
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

| Basket | List<InventoryItem> Basket | | list of inventory items in basket |
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
| Basket | | AddItem(string variant) | if basket is not full add bagel | true
| Basket | | | if basket is full | false
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
| Basket | | RemoveItem(string variant) | if bagel is not in basket | false
| Basket | | | if bagel is in basket | true
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
| Basket | | ChangeCapacity(int capacity, bool IsManager) | if IsManager is true set new capacity | true
| Basket | | | if IsManager is false don't change | false
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
| Basket | int BasketCapacity { get; set; } | | property to set maximum capacity | int
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
| Basket | bool IsInInventory { get; set; } | | property to check if item is in inventory | bool
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
| Basket | bool IsManager { get; set; } | | property to check for manager | bool
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
| Basket | bool IsInBasket { get; set; } | | property to check if item is in basket | bool
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
| Basket | double TotalCost { get; set; } | | property to get cost of basket | double
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Extension2 Receipts:
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
| Basket | string PrintReceipt { get; set; } | | property to print receipt | string
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
| Basket | | AddToReceipt() | for each item in basket add to receipt | string
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Extension1 Discount:
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
| Basket | int BagelCount { get; set; } | | property to get number of bagels in basket| int
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
| Basket | int CoffeeCount { get; set; } | | property to get number of coffee in basket| int
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
| Basket | | getSpecialOffer() | check for special offers and discounts | double
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
| Basket | double TotalCostWithDiscount { get; } | | property to get total cost with discounts | double
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
| BobsInventory | double 6ForDiscount { get; set; } | | property to get special offer | double
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
| BobsInventory | double 12ForDiscount { get; set; } | | property to get special offer | double
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
| BobsInventory | double CoffeeAndBagel { get; set; } | | property to get special offer | double
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

2 changes: 1 addition & 1 deletion exercise.main/exercise.main.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<Nullable>disable</Nullable>
</PropertyGroup>

</Project>
Loading