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

Dennis Osmani #78

Open
wants to merge 23 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
1af7ff8
Domani Model for core requirements is done
Aug 16, 2024
e5823bd
Added the classes needed, and now ready to start with tests and funct…
Aug 16, 2024
4ee6a77
AddItemTest created and failing
Aug 16, 2024
2d3365a
addItems implemented and test is passing
Aug 16, 2024
7732964
removeBagelOrItemTest created and failing
Aug 16, 2024
5bed233
removeBagelOrItem method implemented and test is passing
Aug 16, 2024
0eedeea
ChangeBasketCapacityTest created and failing
Aug 19, 2024
63424e0
changeBasketCapacity method implemented and test is passing
Aug 19, 2024
2000c90
TotalCostTest created and failing
Aug 19, 2024
6e6bf54
totalCost method implemented and test is passing
Aug 19, 2024
fb025f2
GetPriceOfItemTest created and failing
Aug 19, 2024
17da4fe
getPriceOfItem methos implemented and test is passing
Aug 19, 2024
c1a9b2d
starting on extensions by creating user storys and modify the DomainM…
Aug 19, 2024
0f000d4
added a receipt printing method for the terminal, done with extension 2
Aug 19, 2024
f28efa2
Class diagram added
Aug 19, 2024
9b95c80
started on extension 2 - DiscountTest created and failing
Aug 19, 2024
efd9304
Discount not working correctly yet
Aug 20, 2024
4fec509
Discount method implemented and working, done with extension 1
Aug 20, 2024
bb0a093
ReceiptWithDiscount() method implemented and working correctly when p…
Aug 20, 2024
d0104f4
starting on extension 4, starting with updating Domain Model
Aug 21, 2024
24f8be8
Refactoring the code to use Interfaces and Polymorphism, hva added in…
Aug 22, 2024
adb4149
Only refactoring of Discount and ReceiptWithDiscount is left
Aug 22, 2024
6a896fe
not finished with refactoring
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
124 changes: 124 additions & 0 deletions DomainModelCore.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
## 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 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.


-----------------------------------------------------
## EXTENSIONS

1.
As a customer,
So I can choose special offers,
I want customers to be able to see special offers and get discount on the receipt

2.
As a customer,
So I can see what i bought,
I want customers to get a receipt of what items they bought

3.
As a customer,
So i can see the correct price,
I want customers to see the discount if there is one on the items they bought

4. Textmessage
Part 1:
- Users should receive a text message with their order summary,
and delivery time when they complete their order.



| Classes | Methods | Scenario | Outputs |
|-----------------|----------------------------------------------------|----------------------------------------------------|------------|
| `Item` | `Public Item(string id, double price, ` | Item can be either Bagel, Coffe or Filling | Double |
| | `string name, string variant)` | | |
| | | | |
| `Person` | `Public Person(string name, Role role)` | Person can be a Manager or Customer | Person |
| | `Public Enum Role {CUSTOMER, MANAGER}` | | |
| | | | |
| `Inventory` | `Public List<Item> Inventory` | List of all of the Items in Bobs inventory | List<Item> |
| | | | |
| | | | |
| `Basket` | `Inventory inventory` | Property for Bobs inventory | List<Item> |
| | `List<Item> basket = new List<Item>()` | Basket-list for all the Items | List<Item> |
| | | | |
| | `AddItem(Item item)` | User order bagel/filling/coffee to basket-list | bool |
| | | If Bagel/Coffe/filling not in inventory (message) | bool |
| | | If basket is full (message) | bool |
| | | | |
| | `RemoveBagelOrItem(Item item)` | User can remove bagel from basket | bool |
| | | No bagel found to remove (message) | bool |
| | | | |
| | `public int MaxBasketSize { get; set; } = int` | Property for holding and setting full basket value | int |
| | | | |
| | | | |
| | | | |
| | `ChangeBasketCapacity(int capacity, Role role)` | If Role is Manager the basket capacity can | int |
| | | be changed | |
| | | | |
| | `TotalCost()` | Sum of all the items in the basket | Double |
| | | | |
| | `GetPriceOfItem(Item item)` | User can see the price of a specific item | Double |
| | | | |
|-----------------|----------------------------------------------------|----------------------------------------------------|------------|
| | | | |
| `Basket` | `Discount()` | If special offer decided by count of items it | double |
| | | gives a discount | |
| | | | |
| | `Receipt()` | Displays all the items a customer has bought | void |
| | | | |
| | `ReceiptWithDiscount()` | Displays the items bought with discount | void |
| | | (if discount) | |
| | | | |
| | | | |
| | | | |
|-----------------|----------------------------------------------------|----------------------------------------------------|------------|


Empty file added DomainModelExtensions.md
Empty file.
246 changes: 246 additions & 0 deletions exercise.main/Basket.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,246 @@
using System;

using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace exercise.main
{
public class Basket
{
Inventory inventory = new Inventory();
//Person person = new Person("Bob", Role.MANAGER);
private int MAX_BASKET_SIZE { get; set; } = 5;

public List<Item> basketItems = new List<Item>();

public Dictionary<Item, int> countOfItems = new Dictionary<Item, int>();

//Help method for not having to write the long condition check in the if statement in addItem :)
public bool Equals(Item one, Item two)
{
if (one.id == two.id && one.price == two.price && one.name == two.name && one.variant == two.variant)
{
return true;
}
return false;
}

public bool addItem(Item? plainBagel)
{
// initiate max size of basket
if (plainBagel == null)
{
Console.WriteLine("Wrong input!");
return false;
}

if (basketItems.Count < MAX_BASKET_SIZE && inventory.getInventory().Any(item => Equals(item, plainBagel))) {
basketItems.Add(plainBagel);
return true;
}

Console.WriteLine("Basket is full or not in our inventory!");
return false;

}

public bool removeBagelOrItem(Item item)
{
if (!basketItems.Any(x => Equals(x, item)))
{
Console.WriteLine($"{item.name} {item.variant} not in basket!");
return false;
}

basketItems.Remove(item);

Console.WriteLine("Removed: " + item.variant);
return true;
}

public int changeBasketCapacity(int newCapacity, Role role)
{

if (role != Role.MANAGER)
{
Console.WriteLine("Only the manager can change capacity!");
return -1;
}

MAX_BASKET_SIZE = newCapacity;

basketItems.Capacity = MAX_BASKET_SIZE;

Console.WriteLine(basketItems.Capacity);
return basketItems.Capacity;
}

public double totalCost()
{
return Math.Round(basketItems.Sum(item => item.price), 2);
}

public double getPriceOfItem(Item item)
{
if (!inventory.getInventory().Any(x => Equals(x, item)))
{
Console.WriteLine($"{item.name} {item.variant} not in Bobs inventory");
return -1;
}

return item.price;
}

public void Receipt()
{

List<string> itemsCounted = new List<string>();

string receipt = "~~~ Bob's Bagels ~~~" + "\n\n" +
DateTime.Now.ToString() + "\n\n" +
"------------------------" + "\n\n";


basketItems.ForEach(item => {

if (!itemsCounted.Contains(item.id))
{
int itemCount = 0;
foreach (var copy in basketItems)
{
if (copy.id == item.id)
{
itemCount++;
}
}
receipt += $"{item.name} {item.variant} {itemCount} £{item.price * itemCount} \n\n";
itemsCounted.Add(item.id);
}
});

receipt += $"------------------------ \n\nTotal £{totalCost()} \n\nThank you for your order!";

Console.WriteLine(receipt);
}

public double discount()
{

List<string> itemsCounted = new List<string>();

basketItems.ForEach((item) =>
{

if (!itemsCounted.Contains(item.id))
{
int itemCount = 0;
foreach (var copy in basketItems)
{
if (copy.id == item.id)
{
itemCount++;
}
}

countOfItems.Add(item, itemCount);
itemsCounted.Add(item.id);
}
});

double bagAndCof = 1.25;
double sixBagels = 2.49;
double twelBagels = 3.99;

List<Item> cof = inventory.getInventory().Where(item => item.id.Contains("COF")).ToList();
List<Item> bgl = inventory.getInventory().Where(item => item.id.Contains("BGL")).ToList();

if (basketItems.Count == 2 && (cof.Any(i => i.id.Contains(countOfItems.First().Key.id) || i.id.Contains(countOfItems.Last().Key.id))
&& (bgl.Any(i => i.id.Contains(countOfItems.First().Key.id) || i.id.Contains(countOfItems.Last().Key.id)))))
{
return bagAndCof;
}

if (countOfItems.Count > 0)
{

foreach (var item in countOfItems)
{
if (item.Key.id.Contains("BGL") && item.Value == 6)
{
return sixBagels;
}
else if (item.Key.id.Contains("BGL") && item.Value == 12)
{
return twelBagels;
}
else
{
return 0;
}
}
}

return 0;
}

public void ReceiptWithDiscount()
{

double bagAndCof = 1.25;
double sixBagels = 2.49;
double twelBagels = 3.99;

double discountVal = discount();
double totalBagelPrice = 0;

string receipt = "~~~ Bob's Bagels ~~~" + "\n\n" +
DateTime.Now.ToString() + "\n\n" +
"------------------------" + "\n\n";

if (discountVal == bagAndCof)
{
foreach (var item in countOfItems)
{
receipt += $"{item.Key.name} {item.Key.variant} {item.Value} £{item.Key.price * item.Value} \n\n";
}

receipt += $"Discount (£{bagAndCof}) \n" +
$"------------------------ \n\nTotal £{bagAndCof} \n\n You saved a total of \n £{Math.Round(totalCost() - bagAndCof, 2)} on this shop " +
$"\n\nThank you for your order! \n ";

Console.WriteLine(receipt);
}
else if (discountVal == sixBagels || discountVal == twelBagels)
{
//Plain Bagel is less than the discount for 6.. need to make a check in the BGL list in discount
foreach (var item in countOfItems)
{
if (item.Value == 6 || item.Value == 12)
{
totalBagelPrice = (item.Key.price * item.Value);
receipt += $"{item.Key.name} {item.Key.variant} {item.Value} £{totalBagelPrice} \n\n";
}
else
{
receipt += $"{item.Key.name} {item.Key.variant} {item.Value} £{item.Key.price * item.Value} \n\n";
}
}
Console.WriteLine(" TOTALT: " + totalBagelPrice);
double dis = Math.Round(totalBagelPrice - discountVal, 2);

receipt += $"Discount (-£{dis}) \n" +
$"------------------------ \n\nTotal £{totalCost()-dis} \n\n You saved a total of \n £{dis} on this shop " +
$"\n\nThank you for your order! \n ";

Console.WriteLine(receipt);

}
else
{
Receipt();
}
}
}
}
Loading