private decimal CalculateOverweightCharge(ParcelType parcelType, double weight) { switch (parcelType) { case ParcelType.Small: return(weight > smallParcelWeightLimit ? (decimal)(weight - smallParcelWeightLimit) * 2 : 0); case ParcelType.Medium: return(weight > mediumParcelWeightLimit ? (decimal)(weight - mediumParcelWeightLimit) * 2 : 0); case ParcelType.Large: return(weight > largeParcelWeightLimit ? (decimal)(weight - largeParcelWeightLimit) * 2 : 0); case ParcelType.XL: return(weight > xlParcelWeightLimit ? (decimal)(weight - xlParcelWeightLimit) * 2 : 0); case ParcelType.Heavy: return(weight > heavyParcelWeightLimit ? (decimal)(weight - heavyParcelWeightLimit) * 1 : 0); default: throw new Exception($"Unable to determine overweight charge of Parcel Type: {parcelType}"); } }
private decimal CalculateCostBasedOnParcelType(ParcelType parcelType) { switch (parcelType) { case ParcelType.Small: return(3); case ParcelType.Medium: return(8); case ParcelType.Large: return(15); case ParcelType.XL: return(25); case ParcelType.Heavy: return(50); default: throw new Exception($"Unable to determine cost for Parcel Type: {parcelType}"); } }
/// <summary> /// A parcel /// </summary> /// <param name="dimensions">Total size of all dimensions of the parcel in cm</param> /// <param name="weight">Weight of the parcel in kg</param> public Parcel(double dimensions, double weight) { this.parcelType = this.CalculateParcelType(dimensions, weight); this.weight = weight; }
public ParcelCost(ParcelType parcelType, double weight) { this.cost = this.CalculateCostBasedOnParcelType(parcelType); this.overweightCharge = this.CalculateOverweightCharge(parcelType, weight); }
public Parcel(double widthCm, double heightCm, double weightKg = 0) { Dimensions = new ParcelDimensions(widthCm, heightCm); Type = new ParcelType(Dimensions, weightKg); WeightKg = weightKg; }