Repository navigation
Expand file tree
/
Copy pathHealthCalculator.java
More file actions
60 lines (44 loc) · 1.68 KB
/
Copy pathHealthCalculator.java
File metadata and controls
60 lines (44 loc) · 1.68 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import java.util.Scanner;
public class HealthCalculator {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter your gender (M/F): ");
String gender = scanner.next();
System.out.print("Enter your age: ");
int age = scanner.nextInt();
System.out.print("Enter your weight in kg: ");
double weight = scanner.nextDouble();
System.out.print("Enter your height in meters: ");
double height = scanner.nextDouble();
double bmi = calculateBMI(weight, height);
System.out.printf("Your BMI is: %.2f%n", bmi);
if (bmi < 18.5) {
System.out.println("Underweight");
} else if (bmi < 25) {
System.out.println("Normal");
} else if (bmi < 30) {
System.out.println("Overweight");
} else {
System.out.println("Obese");
}
double bmr = calculateBMR(weight, height, age, gender);
if (bmr == -1) {
System.out.println("Invalid gender");
} else {
System.out.printf("Your BMR is: %.2f kcal/day\n", bmr);
}
scanner.close();
}
public static double calculateBMI(double weight, double height) {
return weight / (height * height);
}
public static double calculateBMR(double weight, double height, int age, String gender) {
if (gender.equals("M")) {
return 66 + (13.7 * weight) + (5 * height * 100) - (6.8 * age);
} else if (gender.equals("F")) {
return 665 + (9.6 * weight) + (1.8 * height * 100) - (4.7 * age);
} else {
return 0;
}
}
}