计算BMI

用一个小程序计算BMI

代码如下:

package Day06;

public class BMI {
private String name;
private int age;
private double height;//cm
private double weight;//kg
public static final double KILOGRAMS_PER_POUND = 0.45359237;
public static final double METERS_PER_INCH = 0.0254;

/**
* @param name
* @param age
* @param height
* @param weight
*/
public BMI(String name, int age, double height, double weight) {
this.name = name;
this.age = age;
this.height = height;
this.weight = weight;
}
/**
* @return the name
*/
public String getName() {
return name;
}
/**
* @param name the name to set
*/
public void setName(String name) {
this.name = name;
}
/**
* @return the age
*/
public int getAge() {
return age;
}
/**
* @param age the age to set
*/
public void setAge(int age) {
this.age = age;
}
/**
* @return the height
*/
public double getHeight() {
return this.height;
}

public double getHeightInInches() {
return this.height / METERS_PER_INCH / 100;
}
/**
* @param height the height to set
*/
public void setHeight(double height) {
this.height = height;
}
/**
* @return the weight
*/
public double getWeight() {
return this.weight;
}

public double getWeightInPound() {
return this.weight / KILOGRAMS_PER_POUND;
}

/**
* @param weight the weight to set
*/
public void setWeight(double weight) {
this.weight = weight;
}

public double getBMIValue() {
double heightInMeters = this.height / 100;
return this.weight / (heightInMeters * heightInMeters);
}

public static void main(String[] args) {
BMI bmi = new BMI("JOHN", 18, 180, 70);
System.out.println(bmi.getName());
System.out.println(bmi.getAge());
System.out.println(bmi.getBMIValue());
System.out.println(bmi.getWeightInPound());
System.out.println(bmi.getHeightInInches());
}
}

上一篇:android-Activity的执行流程


下一篇:[转]pymongo常用操作函数