-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBMICalculator.java
48 lines (38 loc) · 1.7 KB
/
BMICalculator.java
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
import java.util.Scanner;
public class BMICalculator {
static Scanner keyboard = new Scanner(System.in);
static double enteredInches, enteredWeight, calcMeter, calcKilo, massIndex;
public static void imperialEntry() {
System.out.println("Welcome to the BMI Calculator");
System.out.println("\nPlease enter your weight in pounds");
enteredWeight = keyboard.nextDouble();
System.out.println("\nPlease enter your height in inches");
enteredInches = keyboard.nextDouble();
keyboard.close();
}
public static void weightConversion (double calcPound) {
calcKilo = (calcPound * 453.59) / 1000;
}
public static void heightConversion (double calcInch) {
calcMeter = (calcInch * 2.54) / 100;
}
public static void calculateIndex(double indexKilo, double indexMeter, double indexPound, double indexInch){
massIndex = (indexKilo / (indexMeter * indexMeter));
}
public static void displayIndex(){
System.out.printf("\nYou weigh %.2f pounds and measure %.2f inches", enteredWeight, enteredInches);
System.out.printf("\nYou weigh %.2f kilograms and measure %.2f meters", calcKilo, calcMeter);
System.out.printf("\nYour BMI is %.1f\n",massIndex);
}
public static void endMessage(){
System.out.println("\nThank you for using the BMI Calculator");
}
public static void main(String []args){
imperialEntry();
weightConversion(enteredWeight);
heightConversion(enteredInches);
calculateIndex(calcKilo, calcMeter, enteredWeight, enteredInches);
displayIndex();
endMessage();
}
}