Created
May 19, 2018 16:29
-
-
Save way2datta/6bf582f00603fe5b7e0fb9e9af91792d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
namespace NMart.Billing | |
{ | |
internal class NMartStore | |
{ | |
private static Dictionary<string, int> CategoryGstRatesInPercentage = new Dictionary<string, int>(); | |
private static Dictionary<string, string> ItemsInCategory = new Dictionary<string, string>(); | |
public static void Main() | |
{ | |
SetupGstRateForCategories(); | |
SetupItemsPerCategory(); | |
Console.WriteLine("Welcome to NMart store"); | |
Console.WriteLine("***************************"); | |
string itemName; | |
int itemQuantity, ratePerUnitItem; | |
ReadUserInput(out itemName, out itemQuantity, out ratePerUnitItem); | |
double finalPrice = CalculateFinalRate(itemName, itemQuantity, ratePerUnitItem); | |
string output = "*******************************************\n" + | |
"Billing Details for " + itemName + ":\n" + | |
"*******************************************\n" + | |
"Quantity: " + itemQuantity + | |
"\nPrice per unit: " + ratePerUnitItem + | |
"\nFinal rate: " + finalPrice; | |
Console.WriteLine(output); | |
Console.WriteLine("\n*********************************\n"); | |
} | |
private static double CalculateFinalRate(string itemName, int itemQuantity, int ratePerUnitItem) | |
{ | |
string categoryName = GetCategory(itemName); | |
int gstPercentageForItem = GetGstPercentage(categoryName); | |
double gstRatePerItem = ratePerUnitItem * gstPercentageForItem / 100.0; | |
double finalPrice = itemQuantity * (ratePerUnitItem + gstRatePerItem); | |
return finalPrice; | |
} | |
private static string GetCategory(string itemName) | |
{ | |
string categoryName = ""; | |
foreach (var item in ItemsInCategory) | |
{ | |
if (item.Key == itemName) | |
{ | |
categoryName = item.Value; | |
break; | |
} | |
} | |
return categoryName; | |
} | |
private static int GetGstPercentage(string categoryName) | |
{ | |
int gstPercentageForItem = 0; | |
foreach (var categoryGstRate in CategoryGstRatesInPercentage) | |
{ | |
if (categoryGstRate.Key == categoryName) | |
{ | |
gstPercentageForItem = categoryGstRate.Value; | |
break; | |
} | |
} | |
return gstPercentageForItem; | |
} | |
private static void ReadUserInput(out string itemName, out int itemQuantity, out int ratePerUnitItem) | |
{ | |
Console.Write("Enter name of item: "); | |
itemName = Console.ReadLine(); | |
Console.Write("Enter quantity of item: "); | |
itemQuantity = int.Parse(Console.ReadLine()); | |
Console.Write("Enter rate per product item: "); | |
ratePerUnitItem = int.Parse(Console.ReadLine()); | |
} | |
private static void SetupGstRateForCategories() | |
{ | |
CategoryGstRatesInPercentage.Add("Food-grains", 0); | |
CategoryGstRatesInPercentage.Add("Furniture", 5); | |
CategoryGstRatesInPercentage.Add("Electronics", 18); | |
CategoryGstRatesInPercentage.Add("Cosmetics", 28); | |
} | |
private static void SetupItemsForCosmetics() | |
{ | |
ItemsInCategory.Add("Shampoo", "Cosmetics"); | |
ItemsInCategory.Add("Perfume", "Cosmetics"); | |
} | |
private static void SetupItemsForElectronics() | |
{ | |
ItemsInCategory.Add("TV", "Electronics"); | |
ItemsInCategory.Add("Mobile", "Electronics"); | |
} | |
private static void SetupItemsForFoodGrains() | |
{ | |
ItemsInCategory.Add("Rice", "Food-grains"); | |
ItemsInCategory.Add("Wheat", "Food-grains"); | |
} | |
private static void SetupItemsForFurniture() | |
{ | |
ItemsInCategory.Add("Sofa", "Furniture"); | |
ItemsInCategory.Add("Chairs", "Furniture"); | |
} | |
private static void SetupItemsPerCategory() | |
{ | |
SetupItemsForFoodGrains(); | |
SetupItemsForFurniture(); | |
SetupItemsForElectronics(); | |
SetupItemsForCosmetics(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment