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

Ali Haider Khan #61

Open
wants to merge 18 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
14 changes: 14 additions & 0 deletions domain-model.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
| Classes | Methods() | Scenario | Output |
|---------|-----------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------|
| Basket | bool addItem(Item item) | bagel is added to the basket if it exists and can be<br>added and it returns true. Else it will return false. | bool, added true, else false |
| | bool removeBagel(Item item) | bagel is removed from the basket if it increases the<br>max capasity for example. | bool, bagel removed true, <br>else false. |
| | bool isFull() | if max capasity of the basket is increased, return<br>true. | bool, true if it is full, else<br>false. |
| | bool changeBasketCapasity(int<br>newcapasity) | if the new capasity is different from the previous<br>one, it will change the capasity. If not, it will <br>return false. | bool, true if capasity changed,<br>else it is false. |
| | string removingNotExisting(Item item) | If the Item list does not contain the item we wanna<br>remove, it will give us a string message that the<br>item does not exist, else it is existing. | string message, item does not<br>exists.<br>string message, item exist. |
| | double calculateTotalCost() | calculating the total costs of items in the basket.<br>giving the price and calculating the sum | double, totalprice of items |
| | double getBagelPrice(string sku) | finding bagel from inventory and returning bagel<br>price. | double, price of the bagel |
| | string getChosenFilling() | finding item with filling from the inventory and<br>chosing a particular filling. | string, gives the filling or<br>string, not existing |
| | double getFillingCost(string variant) | finding item with filling from the inventory and <br>returns the filling price. | double, gives the filling<br>price, else it gives 0 |
|
|Inventory,
Item | |
204 changes: 204 additions & 0 deletions exercise.main/Basket.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,204 @@
using System;
using System.Collections.Generic;
using System.Data.SqlTypes;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


namespace exercise.main

{
public class Basket
{
private Inventory _inventory = new Inventory();

private List<Item> _items = new List<Item> { };

private int _maxcapasity;


public string printreceipt()
{
StringBuilder sb = new StringBuilder();
sb.AppendLine();
sb.AppendLine("Bob's Bagels");
sb.AppendLine();
sb.AppendLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
sb.AppendLine();
sb.AppendLine("-------------------");

double totalprice = 0;

var groupedItem = _items.GroupBy(item => new { item.Variant, item.Name })
.Select(group => new
{
Name = group.Key.Name,
Variant = group.Key.Variant,
Quantity = group.Count(),
ItemPrice = group.First().Price,
TotalPrice = group.Sum(item => item.Price)
});

foreach (var group in groupedItem)
{
var itemname = $"{group.Name} {group.Variant}";
var itemquantity = group.Quantity;
var totalitemprice = group.ItemPrice;
totalprice += totalitemprice;

sb.AppendLine($"{itemname}\t {itemquantity,2}\t £{totalitemprice:F2}");
}

sb.AppendLine();
sb.AppendLine();
sb.AppendLine("------------------");
sb.AppendLine($"Total £{totalprice:F2}");

return sb.ToString();


}

public bool addItem(Item item)
{
if (item == null)
{
return false;
} else if (Items.Count <= _maxcapasity)
{
Items.Add(item);
return true;
} else
{
return false;
}


//if (Item.Count() <= max_capasity)
//{
// Item.Add(item);
// return true;
//} else if (item == null)
//{
// return false;
//}
//return false;

}
public bool removeItem(Item item)
{
if (Items.Count() > _maxcapasity)
{
Items.Remove(item);
return true;
}
return false;

}
public bool isFull()
{
if (Items.Count() <= _maxcapasity)
{
return true;
}
return false;
}

public bool changecapacity(int newcapasity)
{

if (newcapasity > 0 && newcapasity != _maxcapasity)
{
_maxcapasity = newcapasity;
return true;
}
return false;

}
public string removingNotExisting(Item item)
{
if (!Items.Contains(item))
{
return "Item does not exists";
}
return "Item exists";
}

public double getTotalCost()
{
return Items.Sum(item => item.Price);

}

public double getBagelPrice(string sku)
{
Inventory inventory = new Inventory();

Item bagel = inventory.ShopInventory.Find(item => item.Sku == sku);

if (inventory.ShopInventory.Contains(bagel))
{
return bagel.Price;
}
return 0;

}

public string getChosenFilling(string sku)
{
Inventory inventory = new Inventory();

Item bagelwithfilling = inventory.ShopInventory.Find(item => item.Sku == sku);

if (inventory.ShopInventory.Contains(bagelwithfilling))
{
return bagelwithfilling.Variant;
}
return "Not existing";
}

public double getFillingCost(string variant)
{
Inventory inventory = new Inventory();
double fillingprice = 0;

foreach (Item item in inventory.ShopInventory)
{
if (item.Variant == variant)
{
fillingprice = item.Price;
return fillingprice;
}
}
return 0.0d;

}

/* public bool checknonexistsing(string sku)
{
Inventory inventory = new Inventory();

foreach (Item item in Inventory.ShopInventory)
{
if (item.Sku == sku)
{
return true;

}

}
return false;
}
*/



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

public int Maxcapasity { get { return _maxcapasity; } set { _maxcapasity = value; } }


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

namespace exercise.main
{
public class Inventory
{

private List<Item> _shopInventory = new List<Item>();


public Inventory() {

_shopInventory.Add(new Item("BGLO", 0.49, "Bagel", "Onion"));
_shopInventory.Add(new Item("BGLP", 0.39, "Bagel", "Plain"));
_shopInventory.Add(new Item("BGLE", 0.49, "Bagel", "Everything"));
_shopInventory.Add(new Item("BGLS", 0.49, "Bagel", "Sesame"));
_shopInventory.Add(new Item("COFB", 0.99, "Coffee", "Black"));
_shopInventory.Add(new Item("COFW", 1.19, "Coffee", "White"));
_shopInventory.Add(new Item("COFC", 1.29, "Coffee", "Cappucino"));
_shopInventory.Add(new Item("COFL", 1.29, "Coffee", "Latte"));
_shopInventory.Add(new Item("FILB", 0.12, "Filling", "Bacon"));
_shopInventory.Add(new Item("FILE", 0.12, "Filling", "Egg"));
_shopInventory.Add(new Item("FILC", 0.12, "Filling", "Cheese"));
_shopInventory.Add(new Item("FILX", 0.12, "Filling", "Cream Cheese"));
_shopInventory.Add(new Item("FILS", 0.12, "Filling", "Smoked Salmon"));
_shopInventory.Add(new Item("FILH", 0.12, "Filling", "Ham"));

}

public Item GetItembySku(string sku)
{
return _shopInventory.Find(item => item.Sku == sku);
}

public List<Item> ShopInventory { get { return _shopInventory; } }

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

namespace exercise.main
{
public class Item
{


private string _sku;
private double _price;
private string _name;
public string _variant;


public Item()
{

}
public Item(string sku, double price, string name, string variant) {

_sku = sku;
_price = price;
_name = name;
_variant = variant;

}
public string Sku { get { return _sku; } }
public double Price { get { return _price; } }
public string Name { get { return _name; } }

public string Variant { get { return _variant; } }

}

}

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

Basket basket = new Basket();

basket.changecapacity(10);

Item item1 = new Item("BGLO", 0.49, "Bagel", "Onion");
Item item2 = new Item("BGLO", 0.49, "Bagel", "Onion");
Item item3 = new Item("BGLP", 0.39, "Bagel", "Plain");
Item item4 = new Item("BGLE", 0.49, "Bagel", "Everything");

basket.addItem(item1);
basket.addItem(item2);
basket.addItem(item3);
basket.addItem(item4);

string receipt = basket.printreceipt();
Console.WriteLine(receipt);
50 changes: 50 additions & 0 deletions exercise.main/Receipt.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace exercise.main
{
public class Receipt
{
private string _storename;
private List<Item> _purchasedItems = new List<Item>();
private double _totalprice;
private int quantity;

public Receipt(string storename, List<Item> purchasedItems, double totalprice)
{

_storename = storename;
_purchasedItems = purchasedItems;
_totalprice = totalprice;
}

public void printReceipt()
{
Item newItem = new Item("BGLO", 0.49, "Bagel", "Onion");

string sku = newItem.Sku;
double price = newItem.Price;
string name = newItem.Name;
string variant = newItem.Variant;

foreach (var item in PurchasedItems)
{

}

}


public string Storename { get { return _storename; } }
public List<Item> PurchasedItems { get { return _purchasedItems; } }

public double Totalprice { get { return _totalprice; } }

public int Count { get { return count; }

}
}
*/
4 changes: 4 additions & 0 deletions exercise.sln
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "exercise.tests", "exercise.
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{825CCFE7-4F2E-4770-8393-FEB732F66EE4}"
ProjectSection(SolutionItems) = preProject
domain-model.md = domain-model.md
extension1.md = extension1.md
extension2.md = extension2.md
extension3.md = extension3.md
Expand All @@ -34,4 +35,7 @@ Global
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {524196D3-E52F-4BDD-8DB8-A2F11FB8B65C}
EndGlobalSection
EndGlobal
Loading