import java.util.Scanner;
public class Tt {
/** 计算公式:
* 男:[66 + 1.38 x 体重(kg) + 5 x 高度(cm) - 6.8 x 年龄] x 活动量
* 女:[65.5 + 9.6 x 体重(kg) + l.9 x 高度(cm) - 4.7 x 年龄] x 活动量
*/
private static double actRadio = 1.2;//活动量
public static void main (String[] args){
System.out.println(">>计算人体每天摄入热量<<");
System.out.println("请输入性别/体重(KG)/身高(CM)/年龄,例如:男/60/170/25");
Scanner sca = new Scanner(System.in);
String input = sca.nextLine();
while(!"exit".equalsIgnoreCase(input)){
double heat = calcHeat(input);
if(heat==-1){
System.out.println(">>输入格式不正确,请重新输入!");
Scanner sc = new Scanner(System.in);
input = sc.nextLine();
continue;
}else{
System.out.println(">>所需热量为:"+heat+"(Kcal)");
System.out.println(">>请继续输入:");
Scanner sc = new Scanner(System.in);
input = sc.nextLine();
}
}
}
private static double calcHeat(String input){
double heat = -1;
try {
String[] ss = input.split("/");
if(ss[0].equals("男")){
heat = (66+1.38*Integer.parseInt(ss[1])+ 5*Integer.parseInt(ss[2])+6.8*Integer.parseInt(ss[3]))*actRadio;
}else if(ss[0].equals("女")){
heat = (65.5+9.6*Integer.parseInt(ss[1])+ 1.9*Integer.parseInt(ss[2])+4.7*Integer.parseInt(ss[3]))*actRadio;
}else {
throw new Exception();
}
}catch (Exception e){
return -1;
}
return heat;
}
}
public class Calorie {
public static void main(String[] args) {
Calorie c = new Calorie();
//调用CalorieCount方法,传入 体重,性别,身高,年龄参数
double calorie = c.CalorieCount(90,1, 183, 28);
//将结果打印
System.out.println(calorie);
}
/**
*
* @param weight 体重
* @param sex 性别
* @param height 身高
* @param age 年龄
* @return 所需热量
*/
public double CalorieCount(double weight,int sex,double height,int age){
double result = 0;
//表示男人
if(sex == 1){
result = 66 + (13.7*weight)+(5*height)-6.8*age;
}
//表示女人
else if(sex == 2){
result = 65 + (9.6*weight)+(1.7*height)-4.7*age;
}
return result;
}
}
备注:公式是百度所得,计算公式对不对就不保证了。
根据个人的身高、体重、性别、年龄来计算
男性:
66+[13.7x体重(千克)]+[5x身高(厘米)]-6.8x年龄
女性:
65+[9.6x体重(千克)+[1.7x身高(厘米)]-4.7x年龄