private void calcButton_Click(object sender, EventArgs e) { // Collect Form Data For Input Validation var formData = new RawUserInput { WeightInPounds = weightTextbox.Text, HeightFeetIndex = heightFtComboBox.SelectedIndex, HeightInchesIndex = heightInCombobox.SelectedIndex, HeightFeetValue = heightFtComboBox.Text, HeightInchesValue = heightInCombobox.Text, Age = ageTextbox.Text, IsMale = maleButton.Checked, IsFemale = femaleButton.Checked, LossPerWeekIndex = lossPerWeekComboBox.SelectedIndex.ToString(), ActivityLevel = activityLevelComboBox.SelectedIndex.ToString(), MacroParametersIndex = macroComboBox.SelectedIndex.ToString() }; // Validate User Input string inputErrors = formData.ValidateInput(); // If there were errors, notify the user if (!string.IsNullOrEmpty(inputErrors)) { MessageBox.Show(inputErrors, "Input Invalid"); } // If there were no errors, generate the calculation entity and process and display the data else { UserProfile profile = new UserProfile(formData); // Display the results bmiOutputLabel.Text = profile.BodyMassIndex.ToString("0.00"); caloriesOutputLabel.Text = profile.TotalDailyEnergyExpenditure.ToString("0"); macroLabelOutput.Text = $"Macronutrient Distribution: \r\n\t" + $"Protein: { profile.Macros.GramsOfProtein }g " + $"Carbs: { profile.Macros.GramsOfCarbohydrates }g " + $"Fats: { profile.Macros.GramsOfFat }g"; if (profile.BodyMassIndex < 18.5f) { categoryLabel.Text = "Underweight"; } else if (profile.BodyMassIndex > 18.5f & profile.BodyMassIndex < 24.5f) { categoryLabel.Text = "Normal Weight"; } else if (profile.BodyMassIndex > 24.5f & profile.BodyMassIndex < 29.9f) { categoryLabel.Text = "Overweight"; } else if (profile.BodyMassIndex > 30.0f) { categoryLabel.Text = "Obese"; } } }
public UserProfile(RawUserInput userInput) { WeightInPounds = int.Parse(userInput.WeightInPounds); HeightInInches = int.Parse(userInput.HeightFeetValue) * 12 + int.Parse(userInput.HeightInchesValue); Age = int.Parse(userInput.Age); Gender = userInput.IsMale ? Gender.Male : Gender.Female; switch (userInput.ActivityLevel) { case "0": // Sedentary _activityMultiplier = 1.2; break; case "1": // Light _activityMultiplier = 1.375; break; case "2": // Moderate _activityMultiplier = 1.55; break; case "3": // Heavy _activityMultiplier = 1.725; break; case "4": // Athlete _activityMultiplier = 1.9; break; } switch (userInput.LossPerWeekIndex) { case "3": // Lose 2 _weightLossBasedCalorieDeficit = 1000; break; case "2": // Lose 1.5 _weightLossBasedCalorieDeficit = 750; break; case "1": // Lose 1 _weightLossBasedCalorieDeficit = 500; break; case "0": // Lose 0.5 _weightLossBasedCalorieDeficit = 250; break; case "4": // Maintain default: _weightLossBasedCalorieDeficit = 0; break; } switch (userInput.MacroParametersIndex) { case "0": // Maintain Macros = new MacroNutrientBreakdown { MacroParameters = MacroParameters.Maintain, ProteinPercentage = 0.20, GramsOfProtein = (int)Math.Floor(TotalDailyEnergyExpenditure * 0.20 / 4), FatPercentage = 0.30, GramsOfFat = (int)Math.Floor(TotalDailyEnergyExpenditure * 0.30 / 9), CarbohydratePercentage = 0.50, GramsOfCarbohydrates = (int)Math.Floor(TotalDailyEnergyExpenditure * 0.50 / 4) }; _macroParameterAdjustment = 0; break; case "1": // Bulk var adjustedTdee = TotalDailyEnergyExpenditure + 200; int gramsOfProtein = (int)Math.Floor(0.8 * WeightInPounds); int gramsOfFat = (int)Math.Floor(0.5 * WeightInPounds); Macros = new MacroNutrientBreakdown { MacroParameters = MacroParameters.Bulk, GramsOfProtein = gramsOfProtein, GramsOfFat = gramsOfFat, GramsOfCarbohydrates = (int)Math.Floor((adjustedTdee - (4 * gramsOfProtein) - (9 * gramsOfFat)) / 4) }; _macroParameterAdjustment = 200; break; case "2": // Cut Macros = new MacroNutrientBreakdown { MacroParameters = MacroParameters.Cut, ProteinPercentage = 0.40, GramsOfProtein = (int)Math.Floor(TotalDailyEnergyExpenditure * 0.40 / 4), FatPercentage = 0.30, GramsOfFat = (int)Math.Floor(TotalDailyEnergyExpenditure * 0.30 / 9), CarbohydratePercentage = 0.30, GramsOfCarbohydrates = (int)Math.Floor(TotalDailyEnergyExpenditure * 0.30 / 4) }; _macroParameterAdjustment = 0; break; } }