-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBMICalculator.java
More file actions
45 lines (40 loc) · 1.74 KB
/
BMICalculator.java
File metadata and controls
45 lines (40 loc) · 1.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// BMICalculator class is a utility class that's used to calculate the BMI value in both Imperial and Metric systems
public class BMICalculator {
double weightInPounds;
double heightInInches;
double weightInKilos;
double heightInMeters;
// Please declare 4 attributes/properties to represent weight in pounds, height in inches, weight in kilos and height in meters
// Please use this default no arguments constructor to initialize the 4 properties to some initial values
public BMICalculator() {
this.weightInPounds = 150;
this.heightInInches = 65;
this.weightInKilos = 90;
this.heightInMeters = 1.75;
}
// Please implement the calculateBmiImperial() method to take in weight and height to calculate and return the BMI value in the Imperial system
public double calculateBmiImperial(double weight , double height) {
double bmiImperial = (weight * 703)/ (height * height);
return bmiImperial;
}
// Please implement the calculateBmiMetric() method to take in weight and height to calculate and return the BMI value in the Metric system
public double calculateBmiMetric(double weight , double height) {
double bmiMetric = weight / (height * height);
return bmiMetric;
}
// Please implement the getBMICategory() method so that it takes the BMI value and returns the BMI category based on it
public String getBMICategory(double bmi) {
if (bmi >= 0 && bmi < 18.5) {
return "Underweight";
}
else if (bmi >= 18.5 && bmi < 25) {
return "Normal weight";
}
else if (bmi >= 25 && bmi < 30) {
return "Overweight";
}
else {
return "Obese";
}
}
}