internal void RequestUserInput(UserPackage userPackage) { Console.WriteLine("Welcome to our shipping price calculator"); bool allInputsRead = false; while (allInputsRead == false) { if (userPackage.Length == 0) { UserLength(userPackage); } else if (userPackage.Breadth == 0) { UserBreadth(userPackage); } else if (userPackage.Height == 0) { UserHeight(userPackage); } else if (userPackage.Weight == 0) { UserWeight(userPackage); } else { allInputsRead = true; } } }
/// <summary> /// This method may need explaining. The user might not input their smallest value as height and their largest as breadth /// This method sorts the dimensions such that the package is in the most economical orientation /// </summary> /// <param name="userPackageOptimised"></param> /// <param name="userPackage"></param> public void OptimiseUserPackageOrientation(UserPackage userPackageOptimised, UserPackage userPackage) { double[] userPackageArray = { userPackage.Breadth, userPackage.Length, userPackage.Height }; Array.Sort(userPackageArray); userPackageOptimised.Height = userPackageArray[0]; userPackageOptimised.Length = userPackageArray[1]; userPackageOptimised.Breadth = userPackageArray[2]; userPackageOptimised.Weight = userPackage.Weight; }
public void UserWeight(UserPackage clientPackage) { Console.WriteLine("Please input the weight of your parcel in kg then press enter"); string input = Console.ReadLine(); double result = ValidInput(input); if (result != 0) { clientPackage.Weight = result; } }
public void UserBreadth(UserPackage clientPackage) { Console.WriteLine("Please input the breadth of your parcel in mm then press enter"); string input = Console.ReadLine(); double result = ValidInput(input); if (result != 0) { clientPackage.Breadth = result; } }
public static void Main(string[] args) { var userInput = new UserInput(); var userPackage = new UserPackage(); var categorisePackage = new CategorisePackage(); userInput.RequestUserInput(userPackage); categorisePackage.CalculateParcelCost(userPackage); if (userPackage.Cost != 0) { Console.WriteLine("The cost of shipping your parcel is $" + userPackage.Cost); } Console.ReadLine(); }
internal void CalculateParcelCost(UserPackage userPackage) { OptimiseUserPackageOrientation(userPackageOptimised, userPackage); var costList = new List <double> { TestLength(userPackageOptimised.Length), TestBreadth(userPackageOptimised.Breadth), TestHeight(userPackageOptimised.Height), TestWeight(userPackageOptimised.Weight) }; if (!costList.Contains(-1)) { double cost = costList.Max(); userPackage.Cost = cost; } }