50 lines
1.4 KiB
Java
50 lines
1.4 KiB
Java
package Week4_Lab;
|
|
|
|
|
|
public class BMI {
|
|
|
|
private double heightInInches;
|
|
private double weightInPounds;
|
|
private double bmi;
|
|
public BMI(double heightInInches, double weightInPounds){
|
|
this.heightInInches = heightInInches;
|
|
this.weightInPounds = weightInPounds;
|
|
}
|
|
|
|
public double getHeightInInches() {
|
|
return this.heightInInches;
|
|
}
|
|
|
|
public double getWeightInPounds() {
|
|
return this.weightInPounds;
|
|
}
|
|
public void setHeightInInches(double heightInInches) {
|
|
this.heightInInches = heightInInches;
|
|
}
|
|
|
|
public void setWeightInPounds(double weightInPounds) {
|
|
this.weightInPounds = weightInPounds;
|
|
}
|
|
|
|
public double calBMI(double heightInInches, double weightInPounds){
|
|
double heightInMeters = heightInInches * 0.0254;
|
|
double weightInKilograms = weightInPounds * 0.45359237;
|
|
this.bmi = weightInKilograms / (heightInMeters * heightInMeters);
|
|
return this.bmi;
|
|
}
|
|
|
|
public void BMIInterpretation() {
|
|
if (this.bmi < 18.5) {
|
|
System.out.println("Underweight");
|
|
} else if (this.bmi >= 18.5 && this.bmi < 25) {
|
|
System.out.println("Normal");
|
|
} else if (this.bmi >= 25 && this.bmi < 30) {
|
|
System.out.println("Overweight");
|
|
} else if (this.bmi >= 30) {
|
|
System.out.println("Obese");
|
|
}
|
|
}
|
|
|
|
|
|
}
|