Skip to content

Instantly share code, notes, and snippets.

@paritoshmmmec
Last active October 11, 2015 14:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save paritoshmmmec/65076a0e4916c0a8096a to your computer and use it in GitHub Desktop.
Save paritoshmmmec/65076a0e4916c0a8096a to your computer and use it in GitHub Desktop.
Price Calculator
public class ChildInjectionPriceCalculator
{
public double Calculate(int injectionSize)
{
return 0;
}
}
public class TeenInjectionPriceCalculator
{
public double Calculate(int injectionSize)
{
switch (injectionSize)
{
case 30:
return 13;
break;
case 50:
return 650.0 / 30.0;
case 60:
return (780.0 / 30.0);
default:
return 0;
}
}
}
public class AdultInjectionPriceCalculator
{
public double Calculate(int injectionSize)
{
switch (injectionSize)
{
case 30:
return 13;
case 50:
return (750.0 / 30.0);
case 60:
return (900.0 / 30.0);
default:
return 0;
}
}
}
public class AgedInjectionPriceCalculator
{
public double Calculate(int injectionSize)
{
switch (injectionSize)
{
case 30:
return 13;
case 50:
return (600 / 30.0);
case 60:
return (720 / 30.0);
default:
return 0;
}
}
}
public enum AgeGroup
{
Child = 1,
Teen = 2,
Adult = 3,
Senior = 4 //TODO change this name
}
private AgeGroup CalculateAgeGroup(int age)
{
if (age < 12)
return AgeGroup.Child;
if (age >= 12 || age <= 18)
return AgeGroup.Teen;
if (age >= 19 || age <= 65)
return AgeGroup.Teen;
return AgeGroup.Senior;
}
public class UserPreference
{
public bool IsConsulation { get; set; }
public bool IsImaging { get; set; }
public bool IsBloodAnalysis { get; set; }
public bool IsInjection { get; set; }
public int InjectionSize { get; set; }
}
public class Fee
{
public double Consultancy { get; set; }
public double Imaging { get; set; }
public double BloodAnalysis { get; set; }
public double Injection { get; set; }
}
public class FeesFactory
{
public Fee Initialize(AgeGroup ageGroup, int injectionSize)
{
var fee =new Fee();
switch (ageGroup)
{
case AgeGroup.Child:
fee.Consultancy = 25;
fee.Imaging = 55;
fee.BloodAnalysis = 28;
fee.Injection = 0;
return fee;
case AgeGroup.Teen:
fee.Consultancy = 32;
fee.Imaging = 65;
fee.BloodAnalysis = 32;
fee.Injection = new TeenInjectionPriceCalculator().Calculate(injectionSize);
return fee;
case AgeGroup.Adult:
fee.Consultancy = 40;
fee.Imaging = 70;
fee.BloodAnalysis = 40;
fee.Injection = new AdultInjectionPriceCalculator().Calculate(injectionSize);
return fee;
case AgeGroup.Senior:
fee.Consultancy = 30;
fee.Imaging = 60;
fee.BloodAnalysis = 35;
fee.Injection = new AgedInjectionPriceCalculator().Calculate(injectionSize);
return fee;
default:
throw new ArgumentException();
}
}
}
public double CalculatePrice()
{
Console.WriteLine("Quel est l'age du patient?");
var client = Convert.ToInt32(Console.ReadLine());
var ageGroup = CalculateAgeGroup(client);
var userPrefernce = InitializeUserPrefence();
var fee = new FeesFactory().Initialize(ageGroup,userPrefernce.InjectionSize);
if (!userPrefernce.IsImaging)
fee.Imaging = 0;
if (!userPrefernce.IsConsulation)
fee.Consultancy = 0;
if (!userPrefernce.IsBloodAnalysis)
fee.Injection = 0;
if (userPrefernce.IsConsulation || userPrefernce.IsImaging)
{
fee.Imaging = fee.Imaging * 0.75;
}
var finalAmount = fee.Consultancy + fee.Imaging + fee.BloodAnalysis + fee.Injection;
var finalAmountWithTaxes = finalAmount * 1.15;
if (userPrefernce.IsConsulation || userPrefernce.IsBloodAnalysis || userPrefernce.IsInjection)
{
finalAmountWithTaxes = finalAmountWithTaxes - 10;
}
return finalAmountWithTaxes;
}
public UserPreference InitializeUserPrefence()
{
var userPreference = new UserPreference();
Console.WriteLine("La personne a t-elle choisit une consultation?");
userPreference.IsConsulation = Convert.ToString(Console.ReadLine()).ToLower() != "non";
Console.WriteLine("La personne a t-elle choisit une image radio?");
userPreference.IsImaging = Convert.ToString(Console.ReadLine()).ToLower() != "non";
Console.WriteLine("La personne a t-elle choisit une analyze de sang?");
userPreference.IsBloodAnalysis = Convert.ToString(Console.ReadLine()).ToLower() != "non";
Console.WriteLine("La personne a t-elle choisit une injection?");
userPreference.IsInjection = Convert.ToString(Console.ReadLine()).ToLower() == "oui";//DOUBLE CHECK THIS LOGIC
if (userPreference.IsInjection)
{
Console.WriteLine("Quel est la taille de l'injection? (30 - 50 - 60) ");
userPreference.InjectionSize = Convert.ToInt32(Console.ReadLine());
}
return userPreference;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment