/// Constructor To Create RideRepository instance. /// </summary> /// <summary> public InvoiceGenerator(RideType rideType) { this.rideType = rideType; this.rideRepository = new RideRepository(); try { //If Ride type is Premium Then Rates Set For Premium else For Normal. if (rideType.Equals(RideType.PREMIUM)) { this.MINIMUM_COST_PER_KM = 15; this.COST_PER_TIME = 2; this.MINIMUM_FARE = 20; } else if (rideType.Equals(RideType.NORMAL)) { this.MINIMUM_COST_PER_KM = 10; this.COST_PER_TIME = 1; this.MINIMUM_FARE = 5; } } catch (CabInvoiceException) { throw new CabInvoiceException(CabInvoiceException.ExceptionType.INVALID_RIDE_TYPE, "Invalid Ride Type"); } }
//Constructor to create Repositoru instance public InvoiceGenerator(RideType rideType) { this.rideType = rideType; this.rideRepository = new RideRepository(); try { //If Ride type is premium then rates set for premium else for normal if (rideType.Equals(RideType.Premium)) { this.Min_Cost_Per_km = 15; this.Cost_Per_km = 2; this.Min_Fare = 20; } else if (rideType.Equals(RideType.Normal)) { this.Min_Cost_Per_km = 10; this.Cost_Per_km = 1; this.Min_Fare = 5; } else { throw new CabInvoiceException(CabInvoiceException.ExceptionType.Invalid_Ride_Type, "Invalid Ride Type"); } } catch (CabInvoiceException) { throw new CabInvoiceException(CabInvoiceException.ExceptionType.Invalid_Ride_Type, "Invalid Ride Type"); } }
/// <summary> /// Function to Calculate Fare. /// </summary> /// <param name="distance"></param> /// <param name="time"></param> /// <returns></returns> public double CalculateFare(double distance, int time) { double totalFare = 0; try { //Calculating Total Fare. totalFare = distance * MINIMUM_COST_PER_KM + time * COST_PER_TIME; } catch (CabInvoiceException) { if (rideType.Equals(null)) { throw new CabInvoiceException(CabInvoiceException.ExceptionType.INVALID_RIDE_TYPE, "Invalid Ride Type"); } if (distance <= 0) { throw new CabInvoiceException(CabInvoiceException.ExceptionType.INVALID_DISTANCE, "Invalid Distance"); } if (time < 0) { throw new CabInvoiceException(CabInvoiceException.ExceptionType.INVALID_TIME, "Invalid Time"); } } return(Math.Max(totalFare, MINIMUM_FARE)); }
public Invoice_Generator(RideType rideType) { this.rideType = rideType; if (rideType.Equals(RideType.NORMAL)) { this.COST_PER_KM = 10; this.COST_PER_MIN = 1; this.MIN_FARE = 5; } else if (rideType.Equals(RideType.PREMIUM)) { this.COST_PER_KM = 15; this.COST_PER_MIN = 2; this.MIN_FARE = 20; } else { throw new Cab_Invoice_Exception(Cab_Invoice_Exception.ExceptionType.INVALID_RIDE_TYPE, "Ride type is Invalid"); } }