public static double Impact(CarConsumption car) { double fuelemission; switch (car.FuelType.Trim().ToLowerInvariant()) { case "diesel": fuelemission = 26.5; break; case "petrol": fuelemission = 23.2; break; case "gas": fuelemission = 19.0; break; default: return(-1.0); } double impact = (fuelemission * car.Consumption * car.Km) / 100.0; return(impact); }
public ActionResult CalculateImpact(CarConsumption car) { double result = Code.CarProcessing.Impact(car); if (result < 130) { ViewBag.Result = "green"; ViewBag.BoldMsg = "Your result is " + result + " g/km."; ViewBag.NormalMsg = "You are below the limit of 130 g/km and you are not a threat to the environment. Please continue using your car in the same way and also responsibly"; } else { ViewBag.Result = "red"; ViewBag.BoldMsg = "Your result is " + result + " g/km."; ViewBag.NormalMsg = "You are above the limit of 130g/km and you are a threat to the environment by causing pollution. You should put eco exhaust if you have not done so yet or use your car less."; } return(View("Contribution", car)); }