我知道这个问题已被问及我已经阅读了其他实例,但是,我从答案中无法理解。我正在尝试创建一个体脂百分比计算器,我需要将BMI从一个类调用到另一个类,我不知道如何。
namespace ParkerProgramming3
{
public class BMICalc
{
static void Main(string[] args)
{
BMICalc calObj = new BMICalc();
string strName = calObj.GetName();
double dWeight = calObj.GetWeight();
double dHeight = calObj.GetHeight();
double BMI = calObj.GetCalc(dWeight, dHeight);
//Console.Read();
}
public string GetName()
{
Console.WriteLine("Welcome to the BFP Calculator!");
Console.WriteLine("What is your name?");
string strName = Console.ReadLine();
Console.WriteLine("Hello " + strName);
Console.WriteLine("First, we need to calculate your BMI");
return strName;
}
public double GetWeight()
{
Console.WriteLine("What is your weight (in pounds)?");
string sWeight = Console.ReadLine();
double dWeight = Convert.ToDouble(sWeight);
return dWeight;
}
public double GetHeight()
{
Console.WriteLine("What is your height (in inches)?");
string sHeight = Console.ReadLine();
double dHeight = Convert.ToDouble(sHeight);
return dHeight;
}
public double GetCalc(double GetWeight, double GetHeight)
{
double BMI = 703 * GetWeight / (GetHeight * GetHeight);
return BMI;
}
}
}
public class BFPCalc
{
public void BMICalc()
{
}
}