/// <summary> /// This event displays the BMI result and the scale after calculations. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Calculate_Click(object sender, EventArgs e) { if (Imperial.Checked == true) { double height = double.Parse(HeightText.Text); double Weight = double.Parse(WeightText.Text); double BMI; BMI = (Weight * 703) / (height * height); BMIResults.Text = BMI.ToString(); if (BMI <= 18.5) { result.Text = "Underweight"; } else if (BMI > 18.5 && BMI <= 24.9) { result.Text = "Normal"; } else if (BMI > 25 && BMI <= 29.9) { result.Text = "Overweight"; } else if (BMI >= 30) { result.Text = "Obese"; } } if (Metric.Checked == true) { double height = double.Parse(HeightText.Text); double Weight = double.Parse(WeightText.Text); double BMI; BMI = (Weight) / (height * height); BMIResults.Text = BMI.ToString(); if (BMI <= 18.5) { result.Text = "Underweight"; } else if (BMI > 18.5 && BMI <= 24.9) { result.Text = "Normal"; } else if (BMI > 25 && BMI <= 29.9) { result.Text = "Overweight"; } else if (BMI >= 30) { result.Text = "Obese"; } } }
public void TestBMIUnderweight() // unit test for Underweight BMI function { BMICalculator.BMI BMITest = new BMICalculator.BMI { WeightStones = 2, WeightPounds = 6, HeightFeet = 4, HeightInches = 72, }; BMICategory expected = BMICategory.Underweight; BMICategory actual = BMITest.BMICategory; Assert.AreEqual(expected, actual); }
public void TestBMIValue() { BMICalculator.BMI BMITest = new BMICalculator.BMI { WeightStones = 11, WeightPounds = 28, HeightFeet = 1, HeightInches = 36, }; double ExpectedBMI = 12.816362091057519; double ActualBMI = BMITest.BMIValue; Assert.AreEqual(ExpectedBMI, ActualBMI); }
public void TestBMIObese() { BMICalculator.BMI BMITest = new BMICalculator.BMI { WeightStones = 1, WeightPounds = 1, HeightFeet = 1, HeightInches = 1, }; BMICategory expected = BMICategory.Obese; BMICategory actual = BMITest.BMICategory; Assert.AreEqual(expected, actual); }
static void Main(string[] args) { Person man = new Person() { Height = 1.68f, Weight = 72, Gender = GenderType.Man }; Console.WriteLine(BMI.GetBMIResult(man)); Person woman = new Person() { Height = 1.58f, Weight = 40, Gender = GenderType.Woman }; Console.WriteLine(BMI.GetBMIResult(woman)); Console.ReadKey(); }
// Process BMI button private void btn_process_Click(object sender, EventArgs e) { if (centimeters > 0 && kilograms > 0) { try { BMI thisGuy = new BMI(); string outString = thisGuy.BMIString(kilograms, centimeters); MessageBox.Show(outString); } catch { } } else { MessageBox.Show("Please enter data"); } }