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

Felix Mathiasson #71

Open
wants to merge 32 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
0e01f64
Create DOMAIN.md
FelixMathiasson Aug 16, 2024
44f7c43
scratched previous code
FelixMathiasson Aug 16, 2024
0fd4928
Merge branch 'main' of https://github.com/FelixMathiasson/csharp-tdd-…
FelixMathiasson Aug 16, 2024
f9a9399
domain created
FelixMathiasson Aug 16, 2024
4bddc98
Test for inventory check made
FelixMathiasson Aug 16, 2024
94e6367
isInInventory test source code now implemented and all tests pass
FelixMathiasson Aug 16, 2024
4238eb4
test Get Price written
FelixMathiasson Aug 16, 2024
884f9b1
Test source code for Get price implemented and all tests pass
FelixMathiasson Aug 16, 2024
f017187
Testcase for adding to basket written and failed
FelixMathiasson Aug 16, 2024
35fde18
Add to basket source code implpemented and all tests pass
FelixMathiasson Aug 16, 2024
9d89b26
Test code for Showcost added, those tests fail
FelixMathiasson Aug 16, 2024
d740248
Source code for ShowCostTest implmented and all tests pass
FelixMathiasson Aug 16, 2024
aa15221
change capacity test for manager written
FelixMathiasson Aug 19, 2024
1fc62c7
all tests for changecapicity source code implemented and passed
FelixMathiasson Aug 19, 2024
265b217
Test case for manager confirm order written
FelixMathiasson Aug 19, 2024
71cfd8e
Confirm order in manager source code implemented and all tests pass
FelixMathiasson Aug 19, 2024
662aa43
Re-wrote basket to work better with customer. Instead of storing 2 st…
FelixMathiasson Aug 19, 2024
dd94c58
Wrote test cases for Adding to basket, may have gone overboard with d…
FelixMathiasson Aug 19, 2024
ad6da03
source code for Customer add to basket done and all tests pass
FelixMathiasson Aug 19, 2024
f0af0e2
cleaned up unneccesary variable from last commit
FelixMathiasson Aug 19, 2024
7b75f5f
Test code for ShowCost in customer written
FelixMathiasson Aug 19, 2024
ca46215
all tests passed for showcost
FelixMathiasson Aug 19, 2024
e2cd920
Remove from basket in customer test written
FelixMathiasson Aug 19, 2024
fc0f760
Remove item source code implemented and all tests pass
FelixMathiasson Aug 19, 2024
87b6feb
Domain updated for extension 1
FelixMathiasson Aug 19, 2024
eaad368
Discounts for extension 1 now works and all tests pass!
FelixMathiasson Aug 19, 2024
e279a78
domain updated, extension 2
FelixMathiasson Aug 20, 2024
8a01cee
PrintReceipt test written
FelixMathiasson Aug 20, 2024
765a4d8
Receipt done, also shows total saving. Exension 1 + a little of 2
FelixMathiasson Aug 20, 2024
52b35d6
All extensions tested and done
FelixMathiasson Aug 20, 2024
c16045d
Ignore previous commit message, extensions 1-3 are done
FelixMathiasson Aug 20, 2024
1956c04
added class diagram
FelixMathiasson Aug 23, 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
111 changes: 111 additions & 0 deletions DOMAIN.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
this is my domain






|Classes |Methods |Scenarios |output
|__________|_________________________________________|____________________________|______________________________
|Customer |Customer(int funds) |Create a new customer with |--------
| | |funds to spend |
| | | |
| | | |
| |ViewMenu() |Present a menu with |---------
| | |bagels and |
| | |fillings. |
| | | |
| |EXTENTION 1: Showcost |Presents specials in menu |
| | | |
| |AddToBasket(string name, string variant |Manager accepts order |true
| | double remainingfunds) | |
| | | |
| | AddToBasket(string name, string variant | |
| |double remainingfunds,string filling) |Manager declines order. |false
| | | |
| | | |
| | | |
| | | |
| |RemoveItem(string name, string variant) |Removes item if it exists |true
| | |and manager updates capcaity|
| | | |
| | | Itemn does not exist |false
| | | |
| |ShowCost() |Calls basket to output cost |double
| | |of items in basket |
| | | |
| |EXTENSION 1: Showcost() |Discounts oppertunities |double
| | |discovered and applied |
| | | |
| |EXTENSION 2+3: Purchase() |Calls for a manager receipt.| true
| | |Basket is not empty |
| | | Then empties basket |
| | | |
| | |Calls for a manager receipt.| false
| | |Basket is empty |
| | | |
| | | |
|__________|_________________________________________|____________________________|
|Manager | | |
| | | |
| |ConfirmOrder(string namne, string variant| |
| |, double remainingFunds, int basketSize) | |
| | |Funds are sufficient for |true
| | |order, items is on the menu |
| | |and capcaity no full |
| | | |
| | |Funds are insufficient for |false
| | |order or item is not on menu|
| | |or capacity is full |
| | | |
| | | |
| |ChangeCapacity(int newCapacity) |NewCapacity is non-negative |true
| | | |
| | |NewCapacity is negative |false
| | | |
| | EXTENSION 2+3 | |
| | PrintReceipt(Basket basket) |Calls Receipt.PrintReceipt |-------
| | | |
| | | |
|__________|_________________________________________|____________________________|
|Basket | | |
| | ShowCost() |Shows sum of bagels in order|double
| | | |
| | Add(string name, string variant) |order added to basket |------
| | | |
| | | |
| |Remove(string name, string variant) |Item exists in basket |true
| | | |
| | |Item does not exists in |false
| | |basket. |
|__________|_________________________________________|____________________________|
|Inventory | | |
| |IsInInventory(string name, string variant)|Item exists in inventory |true
| | | |
| | |Item does not exist in |false
| | |inventory |
| | | |
| |GetPrice(string name, string variant) |Item exists in inventory |double cost
| | | |
| | |Item does not exist in |-1
| | |inventory |
|__________|_________________________________________|____________________________|
|Receipt |EXTENSION2+3 | |
| | | |
| |PrintReceipt(Basket) |Prints receipt of items in | string
| | |basket |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
|__________|_________________________________________|____________________________|______________________________________




Extension 2
As a customer, I'd like to recieve a receipt, so that I know I was charged correctly.
264 changes: 264 additions & 0 deletions exercise.main/Basket.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,264 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace exercise.main
{
public class Basket
{

public Basket()
{
discounts.Add("BGLP", 0.0);
discounts.Add("BGLE", 0.0);// BaGeL Taste
discounts.Add("BGLS", 0.0);// BaGeL Taste
discounts.Add("BGLO", 0.0);// BaGeL Taste
discounts.Add("COFB", 0.0);
discounts.Add("COFW", 0.0);
discounts.Add("COFC", 0.0);
discounts.Add("COFL", 0.0);
}
public struct BasketItem
{
public string coffeeOrBagel = string.Empty;
public string filling = string.Empty;

public BasketItem(string coffeeOrBagel)
{
this.coffeeOrBagel = coffeeOrBagel;
}
public BasketItem(string coffeeOrBagel, string filling)
{
this.coffeeOrBagel = coffeeOrBagel;
this.filling = filling;
}
}

private double totalDiscount = 0.0;
public Dictionary<string, double> discounts = new Dictionary<string, double>();

Inventory inventory = new Inventory();
public List<BasketItem> basket = new List<BasketItem>();
public void Add(BasketItem item)
{
basket.Add(item);
}

public int GetSize()
{
return basket.Count;
}

public bool OrderInBasket(string name, string variant)
{

foreach (var order in basket)
{
if(name == inventory.GetNameAndVariant(order.coffeeOrBagel).name &&
variant == inventory.GetNameAndVariant(order.coffeeOrBagel).variant)
{
return true;
}

}
return false;
}

public double ShowCost()
{
totalDiscount = 0.0;
double retCost = 0.0;
int bagleAmountTaste = 0;
int bagleAmountPlain = 0;

//these are for coffee discounts later
int cof1 = 0;
int cof2 = 0;
int cof3 = 0;
int cof4 = 0;
foreach(var item in discounts)
{
discounts[item.Key] = 0.0; //just a reset
}

foreach (var item in basket)
{
if(item.coffeeOrBagel == "BGLP") //plain bagle
{
bagleAmountPlain++;
}
else if (item.coffeeOrBagel.Substring(0, 3) == "BGL") // flavorful bagel
{
bagleAmountTaste++;
}
if (item.coffeeOrBagel == "COFB")
{
cof1++; //cheapest
}
else if (item.coffeeOrBagel == "COFW")
{
cof2++; // middle
}
else if (item.coffeeOrBagel == "COFC" )
{
cof3++;//expensive cof
}
else if (item.coffeeOrBagel == "COFL")
{
cof4++;//expensive cof
}
retCost += inventory.GetPrice(item.coffeeOrBagel);
retCost += inventory.GetPrice(item.filling);
}
//time to figure out bagel discount for flavorful
int spare12Taste = bagleAmountTaste % 12;
int discount12 = bagleAmountTaste / 12; // int should just remove the decimals
int spare6Taste = spare12Taste % 6;
int discount6 = spare12Taste / 6;// int should just remove the decimals

discounts["BGLT"] = (double)discount12 * 1.89 + (double)discount6 * 0.45;
totalDiscount += (double)discount12 * 1.89 + (double)discount6 * 0.45;
retCost -= (double)discount12 * 1.89;
retCost -= (double)discount6 * 0.45;

//time to figure out bagel discount for plain
int sparePlain = bagleAmountPlain % 12;
discount12 = bagleAmountPlain / 12; // int should just remove the decimals
discounts["BGLP"] = (double)discount12 * 0.69;

totalDiscount += (double)discount12 * 0.69;
retCost -= (double)discount12 * 0.69;
//retCost -= (double)discount6 * 0.45;
// I will not implement a discount on 6 plain bagles as
// buying them induvidually costs 2.34 and the "discount" is 2.49
// I will not be scamming my customers ;)

//for coffe we will use the plain bagels first so the
//customer gets the cheaper bagel discounted. This is how
// most businisses do it

for(int i = 0; i < cof1; i++) //black
{
if (sparePlain > 0)
{
sparePlain--;
retCost -= 0.13;
totalDiscount += 0.13;
discounts["COFB"] += 0.13;
}
else if (spare6Taste > 0)
{
spare6Taste--;
retCost -= 0.23;
totalDiscount += 0.23;
discounts["COFB"] += 0.23;
}
}
for (int i = 0; i < cof2; i++)//white/
{
if (sparePlain > 0)
{
sparePlain--;
retCost -= 0.33;
totalDiscount += 0.33;
discounts["COFW"] += 0.33;
}
else if (spare6Taste > 0)
{
spare6Taste--;
retCost -= 0.43;
totalDiscount += 0.43;
discounts["COFW"] += 0.43;
}
}
for (int i = 0; i < cof3; i++)// capuccino
{
if (sparePlain > 0)
{
sparePlain--;
retCost -= 0.43;
totalDiscount += 0.43;
discounts["COFC"] += 0.43;
}
else if (spare6Taste > 0)
{
spare6Taste--;
retCost -= 0.53;
totalDiscount += 0.53;
discounts["COFC"] += 0.53;
}
}
for (int i = 0; i < cof4; i++)// latte
{
if (sparePlain > 0)
{
sparePlain--;
retCost -= 0.43;
totalDiscount += 0.43;
discounts["COFL"] += 0.43;
}
else if (spare6Taste > 0)
{
spare6Taste--;
retCost -= 0.53;
totalDiscount += 0.53;
discounts["COFL"] += 0.53;
}
}
discounts["BGLO"] = discounts["BGLT"];
discounts["BGLE"] = discounts["BGLT"];
discounts["BGLS"] = discounts["BGLT"];
discounts["BGLT"] = 0.0;

foreach (var item in discounts)
{
discounts[item.Key] = Math.Round(item.Value, 2);
}

return Math.Round(retCost, 2);
}

public double GetDiscount()
{
return Math.Round(this.totalDiscount, 2);
}
public bool RemoveFromBasket(string name, string variant)
{
string code = inventory.GetCode(name, variant);
if(name == "Coffee" || name == "Bagel")
{
for(int i = 0; i < basket.Count; i++)
{
if (basket[i].coffeeOrBagel == code)
{
basket.RemoveAt(i);
return true;
}
}
}
if (name == "Filling")
{
for (int i = 0; i < basket.Count; i++)
{
if (basket[i].filling == code)
{
BasketItem replaceItem = basket[i];
replaceItem.filling = string.Empty;
return true;
}
}
}
return false;
}

public void ClearBasket()
{
basket.Clear();
}


}
}
Loading