package com.itheima.demo;
import java.util.Scanner;
public class AllTest {
public static void main(String[] args) {
//健康计算器
Scanner sc=new Scanner(System.in);
//1、让用户输入自己的个人信息:身高、体重、性别、年龄
System.out.println("请输入您的身高:");
double height=sc.nextDouble();
System.out.println("请输入您的体重:");
double weight=sc.nextDouble();
System.out.println("请输入您的性别:");
String sex=sc.next();
System.out.println("请输入您的年龄:");
int age=sc.nextInt();
double bmi=calcBMI(height,weight);
System.out.println("BMI值为:" + bmi);
double bmr=calcBMR(height,weight,age,sex);
System.out.println("BMR值为:" + bmr);
}
//2、根据个人信息,计算BMI指数(把数据交给一个独立的方法来计算并返回这个结果)
public static double calcBMI(double height,double weight)
{
return weight/(height*height);
}
//3、根据个人信息,计算BMR指数(把数据交给一个独立的方法来计算并返回这个结果)
public static double calcBMR(double height,double weight,int age,String sex)
{double bmr=0;
if("男".equals(sex))
{
bmr=13.397*weight+4.799*height-5.677*age+88.362;
}
else
{
bmr=9.247*weight+3.098*height-4.330*age+447.593;
}
return bmr;
}
}