Skip to content

Commit

Permalink
Added Tax calculation system on Total food price based on the type of…
Browse files Browse the repository at this point in the history
… restraunt by using strategy pattern
  • Loading branch information
gulershad committed Apr 5, 2019
1 parent 2c91c6c commit 37350d6
Show file tree
Hide file tree
Showing 45 changed files with 181 additions and 216 deletions.
5 changes: 1 addition & 4 deletions FoodBuilding/Meal.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
using FoodDeliveryApp.FoodDeliveryAppModel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FoodDeliveryApp.Ordering
{
public class Meal
{
private List<FoodMenuModel> foodItems = new List<FoodMenuModel>();
private readonly List<FoodMenuModel> foodItems = new List<FoodMenuModel>();

public void AddFoodItem(List<FoodMenuModel> items)
{
Expand Down
7 changes: 7 additions & 0 deletions FoodCostTaxCalculation/ITaxCalculator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace FoodDeliveryApp.FoodCostTaxCalculation
{
public interface ITaxCalculator
{
double CalculateTax(double price, double tax, bool imported);
}
}
20 changes: 20 additions & 0 deletions FoodCostTaxCalculation/OneStarTaxCalculator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using FoodDeliveryApp.Utils;

namespace FoodDeliveryApp.FoodCostTaxCalculation
{
public class OneStarTaxCalculator : ITaxCalculator
{
public double CalculateTax(double price, double localTax, bool imported)
{
double tax = price * localTax;

if (imported)
tax += (price * 0.5);

//rounds off to nearest 0.05;
tax = TaxUtil.RoundOff(tax);

return tax;
}
}
}
17 changes: 17 additions & 0 deletions FoodCostTaxCalculation/TaxCalculationContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
namespace FoodDeliveryApp.FoodCostTaxCalculation
{
public class TaxCalculationContext
{
private readonly ITaxCalculator taxCalculator;

public TaxCalculationContext(ITaxCalculator taxCalculator)
{
this.taxCalculator = taxCalculator;
}

public double GetCalculatedTax(double price, double tax, bool imported)
{
return taxCalculator.CalculateTax(price, tax, imported);
}
}
}
20 changes: 20 additions & 0 deletions FoodCostTaxCalculation/ThreeStarTaxCalculator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using FoodDeliveryApp.Utils;

namespace FoodDeliveryApp.FoodCostTaxCalculation
{
public class ThreeStarTaxCalculator
{
public double CalculateTax(double price, double localTax, bool imported)
{
double tax = price * localTax;

if (imported)
tax += (price * 2.5);

//rounds off to nearest 0.05;
tax = TaxUtil.RoundOff(tax);

return tax;
}
}
}
20 changes: 20 additions & 0 deletions FoodCostTaxCalculation/TwoStarTaxCalculator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using FoodDeliveryApp.Utils;

namespace FoodDeliveryApp.FoodCostTaxCalculation
{
public class TwoStarTaxCalculator : ITaxCalculator
{
public double CalculateTax(double price, double localTax, bool imported)
{
double tax = price * localTax;

if (imported)
tax += (price * 1.5);

//rounds off to nearest 0.05;
tax = TaxUtil.RoundOff(tax);

return tax;
}
}
}
6 changes: 6 additions & 0 deletions FoodDeliveryApp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="FoodCostTaxCalculation\ITaxCalculator.cs" />
<Compile Include="FoodCostTaxCalculation\OneStarTaxCalculator.cs" />
<Compile Include="FoodCostTaxCalculation\TaxCalculationContext.cs" />
<Compile Include="FoodCostTaxCalculation\ThreeStarTaxCalculator.cs" />
<Compile Include="FoodCostTaxCalculation\TwoStarTaxCalculator.cs" />
<Compile Include="FoodDeliveryAppModel\FoodMenuModel.cs" />
<Compile Include="FoodDeliveryAppModel\RestaurantModel.cs" />
<Compile Include="FoodBuilding\Meal.cs" />
Expand Down Expand Up @@ -74,6 +79,7 @@
<Compile Include="Tracking\FoodDelivery.cs" />
<Compile Include="Tracking\ICustomers.cs" />
<Compile Include="Tracking\Restaurant.cs" />
<Compile Include="Utils\TaxUtil.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
Expand Down
Binary file modified FoodDeliveryApp.v12.suo
Binary file not shown.
36 changes: 5 additions & 31 deletions FoodDeliveryAppModel/RestaurantModel.cs
Original file line number Diff line number Diff line change
@@ -1,39 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FoodDeliveryApp.FoodDeliveryAppModel
namespace FoodDeliveryApp.FoodDeliveryAppModel
{
public class RestaurantModel
{
private string restaurantId;
public string RestaurantId
{
get { return restaurantId; }
set { restaurantId = value; }
}
public string RestaurantId { get; set; }

private string name;
public string Name
{
get { return name; }
set { name = value; }
}
public string Name { get; set; }

private string address;
public string Address
{
get { return address; }
set { address = value; }
}
public string Address { get; set; }

private int rating;
public int Rating
{
get { return rating; }
set { rating = value; }
}
public int Rating { get; set; }
}
}
16 changes: 5 additions & 11 deletions FoodDeliveryAppModel/UserModel.cs
Original file line number Diff line number Diff line change
@@ -1,20 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FoodDeliveryApp.FoodDeliveryAppModel
namespace FoodDeliveryApp.FoodDeliveryAppModel
{
public class UserModel
{
public String UserId { get; set; }
public string UserId { get; set; }

public String UserName { get; set; }
public string UserName { get; set; }

public String PhoneNumber { get; set; }
public string PhoneNumber { get; set; }

public String Address { get; set; }
public string Address { get; set; }

public double Amount { get; set; }
}
Expand Down
16 changes: 10 additions & 6 deletions FoodDeliveryDriver/MealBuilderDriver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
using FoodDeliveryApp.Ordering;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using FoodDeliveryApp.FoodCostTaxCalculation;

namespace FoodDeliveryApp.FoodDeliveryDriver
{
Expand All @@ -23,9 +21,15 @@ public double BuildMealForUser(List<FoodMenuModel> selectedMealItems)
MealBuilder mealBuilder = new MealBuilder();
mealBuilder.PrepareMeal(selectedMealItems);
mealBuilder.meal.ShowItems();
var totalCost = mealBuilder.meal.GetCost();
Console.WriteLine("Total Cost(Rs.): {0}", totalCost);
return totalCost;
var foodCost = mealBuilder.meal.GetCost();

//Calculation of Tax
var taxCalculationContext = new TaxCalculationContext(new OneStarTaxCalculator());
var taxAmount = taxCalculationContext.GetCalculatedTax(foodCost, 0.05, false);
var totalCostofFood = foodCost + taxAmount;
Console.WriteLine("Total Cost(Rs.): {0}", totalCostofFood);
Console.WriteLine("Total Tax(Rs.): {0}", taxAmount);
return totalCostofFood;
}
}
}
4 changes: 0 additions & 4 deletions FoodDeliveryDriver/MealMenuIteratorDriver.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
using FoodDeliveryApp.FoodDeliveryAppModel;
using FoodDeliveryApp.RestaurantFoodMenu;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FoodDeliveryApp.FoodDeliveryDriver
{
Expand Down
3 changes: 0 additions & 3 deletions FoodDeliveryDriver/MealOrderDriver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
using FoodDeliveryApp.OrderAndCancellation;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FoodDeliveryApp.FoodDeliveryDriver
{
Expand Down
4 changes: 1 addition & 3 deletions FoodDeliveryDriver/MealSelectorDriver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FoodDeliveryApp.FoodDeliveryDriver
{
Expand All @@ -23,7 +21,7 @@ public List<FoodMenuModel> MealSelectionbyUser(List<FoodMenuModel> foodMenu)
{
Console.WriteLine("Enter food Id:");
var foodId = Console.ReadLine();
var foodItem = foodMenu.Where(e => e.FoodId == foodId).FirstOrDefault();
var foodItem = foodMenu.FirstOrDefault(e => e.FoodId == foodId);
if (foodItem != null)
{
Console.WriteLine("You Selected Below food Item:");
Expand Down
4 changes: 0 additions & 4 deletions FoodDeliveryDriver/OrderTrackingDriver.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
using FoodDeliveryApp.FoodDeliveryAppModel;
using FoodDeliveryApp.Tracking;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace FoodDeliveryApp.FoodDeliveryDriver
{
Expand Down
3 changes: 0 additions & 3 deletions FoodDeliveryDriver/RestaurantSearchDriver.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FoodDeliveryApp.RestaurantSearch
{
Expand Down
11 changes: 2 additions & 9 deletions OrderAndCancellation/CancelFood.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@
using FoodDeliveryApp.FoodDeliveryAppModel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FoodDeliveryApp.OrderAndCancellation
namespace FoodDeliveryApp.OrderAndCancellation
{
public class CancelFood : IFoodOrderCommands
{
private Food food;
private readonly Food food;
public string OrderId;

public CancelFood(Food food)
Expand Down
9 changes: 2 additions & 7 deletions OrderAndCancellation/Customer.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
using FoodDeliveryApp.Ordering;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections.Generic;

namespace FoodDeliveryApp.OrderAndCancellation
{
public class Customer
{
List<IFoodOrderCommands> orderList = new List<IFoodOrderCommands>();
readonly List<IFoodOrderCommands> orderList = new List<IFoodOrderCommands>();

public void TakeOrder(IFoodOrderCommands order)
{
Expand Down
4 changes: 0 additions & 4 deletions OrderAndCancellation/Food.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
using FoodDeliveryApp.FoodDeliveryAppModel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FoodDeliveryApp.OrderAndCancellation
{
Expand Down
9 changes: 1 addition & 8 deletions OrderAndCancellation/IFoodOrderCommands.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
using FoodDeliveryApp.FoodDeliveryAppModel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FoodDeliveryApp.OrderAndCancellation
namespace FoodDeliveryApp.OrderAndCancellation
{
public interface IFoodOrderCommands
{
Expand Down
6 changes: 1 addition & 5 deletions OrderAndCancellation/OrderFood.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
using FoodDeliveryApp.FoodDeliveryAppModel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FoodDeliveryApp.OrderAndCancellation
{
public class OrderFood : IFoodOrderCommands
{
private Food food;
private readonly Food food;
public List<FoodMenuModel> FoodItems;
public UserModel User;
public string OrderId;
Expand Down
9 changes: 0 additions & 9 deletions Program.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@
using FoodDeliveryApp.FoodDeliveryAppModel;
using FoodDeliveryApp.OrderAndCancellation;
using FoodDeliveryApp.Ordering;
using FoodDeliveryApp.RestaurantFoodMenu;
using FoodDeliveryApp.RestaurantSearch;
using FoodDeliveryApp.Tracking;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Threading;
using FoodDeliveryApp.FoodDeliveryDriver;

namespace FoodDeliveryApp
Expand Down
Loading

0 comments on commit 37350d6

Please sign in to comment.