예제 #1
0
 private void DisplayResults()
 {
     lblBMIOutput.Text            = bmiCalculator.CalculateBMI().ToString("f2");
     lblWeightCategoryOutput.Text = bmiCalculator.BMIWeightCategory().ToString();
     lblBMIMessageOutput.Text     = bmiCalculator.normalBMIMessage;
     grpResults.Text             = "Name : " + employee.Name;
     lblNormalWeightDisplay.Text = bmiCalculator.GetMessage();
 }
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            BMICalculator bmicalc = new BMICalculator();

            var    feetOrMeters = Height_Input.Text;
            var    inches       = Height_Input_Inches.Text;
            var    metric       = Metric_RadioBtn.IsChecked;
            var    unit         = bmicalc.GetUnitType((bool)metric);
            double?weight       = null;
            double?height;
            double?bmi    = null;
            string status = "";
            string range  = "enter valid height and weight to display range";
            string name   = FirstName_Input.Text + " " + LastName_Input.Text;

            if ((name.Trim() == "") || (name == null))
            {
                name = "Jan Alleman";
            }
            ResultsGroupBox.Header = "Results: " + name;
            string heightInvalidMessage;

            height = bmicalc.ProcessHeight(feetOrMeters, inches, metric, out heightInvalidMessage);
            if (height == null)
            {
                ErrorMessages.ReadErrorMessageOnce(heightInvalidMessage);
            }

            string weightInvalidMessage;

            weight = bmicalc.ProcessWeight(Weight_Input.Text, (bool)metric, out weightInvalidMessage);
            if (weight == null)
            {
                ErrorMessages.ReadErrorMessageOnce(weightInvalidMessage);
            }

            if (bmicalc.CalculateIfWeightAndHeightAreNotNull(weight, height))
            {
                bmi    = bmicalc.CalculateBMI(height, weight, unit);
                status = bmicalc.CalculateNutritionalStatusFromBMI(bmi);
                range  = bmicalc.ProcessNormalBMIRange(height, unit, status);
            }
            else
            {
                Height_Input.Text        = "";
                Height_Input_Inches.Text = "";
                if (weight == null)
                {
                    Weight_Input.Text = "";
                }
            }

            Bmi_Results.Content  = bmi;
            Bmi_Category.Content = status;

            NormalWeightLabel.Content = range;
            ErrorMessages.ResetErrorCounter();
        }
예제 #3
0
        public IActionResult Calculate(BMICalculator model)
        {
            if (IsValid(model))
            {
                model.CalculateBMI();
                model.SetWeightStatus();

                TempData["result"]       = true;
                TempData["BMI"]          = Math.Round(model.BodyMassIndex, 2);
                TempData["WeightStatus"] = model.WeightStatus;
            }
            return(View());
        }
예제 #4
0
        public void MetricCalculator_Test(double height, double weight, double expectedBmi)
        {
            Employee emp = new Employee();

            emp.Name   = "Test";
            emp.Height = height;
            emp.Weight = weight;
            BMICalculator calculator = MetricCalculator.GetInstance(emp);

            string bmi = calculator.CalculateBMI().ToString("f2");

            calculator.CalculateWeight(calculator.BMI);

            Assert.Multiple(() =>
            {
                Assert.AreEqual(calculator.unit, "kg", "Check unit");
                Assert.AreEqual(calculator.Type, UnitTypes.Metric, "Check unit Type");
                Assert.AreEqual(bmi, expectedBmi.ToString("f2"), "Check BMI");
            });
        }
예제 #5
0
        public ActionResult Oblicz(PersonBMI model)
        {
            if (ModelState.IsValid)
            {
                ViewBag.Dane = "Twoje BMI to:" + _bmiCalculator;
                var bmi = _bmiCalculator.CalculateBMI(model.masa, model.wzrost);
                if (bmi > 25)
                {
                    ViewBag.Message = " Masz nadwagę, musisz schudnąć";
                }
                else if (bmi < 19)
                {
                    ViewBag.Message = " Masz niedowagę, musisz przytyć";
                }
                else
                {
                    ViewBag.Message = "Twoja waga jest prawidłowa";
                }
            }


            return(View("Index", model));
        }
        public void BMIInImperialUnits()
        {
            //Arrange
            calculator.UnitType = UnitTypes.Imperial;

            calculator.WeightInStones = 5;
            calculator.WeightInPounds = 6;

            calculator.HeightInFeet   = 7;
            calculator.HeightInInches = 8;

            //Act
            calculator.CalculateBMI();

            //Assert
            Assert.That(calculator.BodyMassIndex, Is.EqualTo(6.31));
        }