public static void Main()
NumberOfPreviousOwners = 1,
var expectedCorrectEstimate = 24813.4m;
var calculatedEstValue = new PriceDeterminator().DetermineCarPrice(car);
if (expectedCorrectEstimate == calculatedEstValue)
Console.WriteLine($"Calculated value was correct: {calculatedEstValue}");
Console.WriteLine($"Calculated value should have been: {expectedCorrectEstimate} but returned: {calculatedEstValue}");
public decimal PurchaseValue { get; set; }
public int AgeInMonths { get; set; }
public int NumberOfMiles { get; set; }
public int NumberOfPreviousOwners { get; set; }
public int NumberOfCollisions { get; set; }
public string Make { get; set; }
public class PriceDeterminator
protected decimal CurrentEstimate { get; set; } = 0.0M;
public decimal DetermineCarPrice(Car car)
CurrentEstimate = car.PurchaseValue;
var noPrevOwnerAdd10 = PriceOwners(car);
private void PriceAccidents(Car car)
if (car.NumberOfCollisions > 4)
CurrentEstimate *= (decimal)Math.Pow(0.98, 5.0);
CurrentEstimate *= (decimal)Math.Pow(0.98, car.NumberOfCollisions);
private void PriceProfit(Car car)
var maxEst = (car.PurchaseValue * 0.90M);
if (CurrentEstimate > maxEst)
CurrentEstimate = maxEst;
private void Resell(Car car)
switch (car.Make.ToUpperInvariant())
CurrentEstimate = 1.05M * CurrentEstimate;
private bool PriceOwners(Car car)
if (car.NumberOfPreviousOwners > 2)
CurrentEstimate *= 0.75M;
if (car.NumberOfPreviousOwners < 1)
private void PriceMiles(Car car)
if (car.NumberOfMiles >= 150000)
CurrentEstimate *= (decimal)Math.Pow(.998, 150);
var k = (int)Math.Floor((double)car.NumberOfMiles / 1000);
CurrentEstimate *= (decimal)Math.Pow(.998, k);
private void PriceAge(Car car)
if (car.AgeInMonths > 120)
this.CurrentEstimate *= (decimal)(Math.Pow(0.995, 120));
this.CurrentEstimate *= (decimal)(Math.Pow(0.995, car.AgeInMonths));