Write a C#(static void Main(string[] args) format) two-class solution to calcula
ID: 3700500 • Letter: W
Question
Write a C#(static void Main(string[] args) format) two-class solution to calculate and display a person’s body mass index (BMI). BMI is an internationally used measure of obesity. Depending on where you live, the Imperial BMI formula or the Metric Imperial Formula is used. Once the BMI is calculated, display a message of the person’s status. Prompt the user for both their weight and height. The BMI status categories, as recognized by the U.S. Department of Health & Human Services, are given in the following table: BMI Weight Status Below 18.5 Underweight 18.5–24.9 Normal 25–29.9 Overweight 30 & above Obese Provide constructors and methods so that both imperial and metric objects can be instantiated. Use the second class to test your design.
I keep getting erros...Please help!
Explanation / Answer
using System;
namespace MyBMI
{
class BMI
{
double weight;
double height;
// default constructor
public BMI()
{
this.weight = 0;
this.height = 1;
}
// constructor
public BMI(double weight, double height)
{
this.weight = weight;
this.height = height;
}
public void getStatus()
{
// BMI = weight / height^2
double bmi = this.weight / ( this.height * this.height );
if( bmi < 18.5 )
Console.WriteLine("Underweight");
else if( bmi < 24.9 )
Console.WriteLine("Normal");
else if( bmi < 29.9 )
Console.WriteLine("Overweight");
else
Console.WriteLine("Obese");
}
}
public class Test
{
public static void Main(string[] args)
{
Console.WriteLine("Enter weight : ");
double weight = Convert.ToDouble(Console.ReadLine());
Console.WriteLine("Enter height : ");
double height = Convert.ToDouble(Console.ReadLine());
// create an object of BMI class
BMI ob = new BMI(weight, height);
ob.getStatus();
}
}
}
Sample Output
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.