1 public class BMI {
2 private String name;
3 private int age;
4 private double weight;
5 private double height;
6 public static final double KILOGRAMS_PER_POUND = 0.45359237;
7 public static final double METERS_PER_INCH = 0.0254;
8
9 public BMI(String name, int age, double weight, double height) {
10 this.name = name;
11 this.age = age;
12 this.weight = weight;
13 this.height = height;
14 }
15
16 public BMI(String name, double weight, double height) {
17 this(name, 20, weight, height);
18 }
19
20 public double getBMI() {
21 double bmi = weight * KILOGRAMS_PER_POUND /
22 ((height * METERS_PER_INCH) * (height * METERS_PER_INCH));
23 return Math.round(bmi * 100) / 100.0;
24 }
25
26 public String getStatus() {
27 double bmi = getBMI();
28 if (bmi < 18.5)
29 return "Underweight";
30 else if (bmi < 25)
31 return "Normal";
32 else if (bmi < 30)
33 return "Overweight";
34 else
35 return "Obese";
36 }
37
38 public String getName() {
39 return name;
40 }
41
42 public int getAge() {
43 return age;
44 }
45
46 public double getWeight() {
47 return weight;
48 }
49
50 public double getHeight() {
51 return height;
52 }
53 }