Created
April 12, 2018 16:21
-
-
Save way2datta/3ff710f216cd977c1c2e1ca7bf14bceb 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>(); | |
private static void Main() | |
{ | |
CategoryGstRatesInPercentage.Add("Food-grains", 0); | |
CategoryGstRatesInPercentage.Add("Furniture", 5); | |
CategoryGstRatesInPercentage.Add("Electronics", 18); | |
CategoryGstRatesInPercentage.Add("Cosmetics", 28); | |
ItemsInCategory.Add("Rice", "Food-grains"); | |
ItemsInCategory.Add("Wheat", "Food-grains"); | |
ItemsInCategory.Add("Sofa", "Furniture"); | |
ItemsInCategory.Add("Chairs", "Furniture"); | |
ItemsInCategory.Add("TV", "Electronics"); | |
ItemsInCategory.Add("Mobile", "Electronics"); | |
ItemsInCategory.Add("Shampoo", "Cosmetics"); | |
ItemsInCategory.Add("Perfume", "Cosmetics"); | |
Console.WriteLine("Welcome to NMart store"); | |
Console.WriteLine("***************************"); | |
Console.Write("Enter name of item: "); | |
string itemName = Console.ReadLine(); | |
Console.Write("Enter quantity of item: "); | |
int itemQuantity = int.Parse(Console.ReadLine()); | |
Console.Write("Enter rate per product item: "); | |
int ratePerUnitItem = int.Parse(Console.ReadLine()); | |
string categoryName = ""; | |
foreach (var item in ItemsInCategory) | |
{ | |
if (item.Key == itemName) | |
{ | |
categoryName = item.Value; | |
break; | |
} | |
} | |
int gstPercentageForItem = 0; | |
foreach (var categoryGstRate in CategoryGstRatesInPercentage) | |
{ | |
if (categoryGstRate.Key == categoryName) | |
{ | |
gstPercentageForItem = categoryGstRate.Value; | |
break; | |
} | |
} | |
double finalPrice = itemQuantity * (ratePerUnitItem + ratePerUnitItem * gstPercentageForItem / 100.0); | |
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"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment