-
Language
Java using Scanner
-
Description
Create an Ideal Weight application that accepts input for:
- A person's name
- A person's height
-The system of measurement they wish to use (metric or imperial).
The program will use the person's height to calculate his/her ideal healthy weight using a formula produced from the formula for body mass index (BMI). The BMI is a statistical measurement which compares a person's weight and height.
Though it does not actually measure the percentage of body fat, it is a useful tool to estimate a healthy body weight based on a person s height. According to the BMI, a value of 18.5 to 25 is considered healthy.
In this program, allow the user to use either the imperial measurements or metric to calculate a healthy weight.
Metric: Weight (kg) = height (metres) × height (metres) × 25
Imperial: Weight (pounds) = height (inches) × height (inches) × 25 ÷ 703
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
public class IdealWeightCalculator {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int system_of_measurement;
double healthy_weight, height;
String person_name;
System.out.print("Enter the person name: ");
person_name = in.nextLine();
System.out.print("Enter the value of height: ");
height = in.nextDouble();
in.nextLine();
System.out.println("Select the value of system of measurement.");
System.out.println("\t1.- metric");
System.out.println("\t2.- imperial");
System.out.print("\t: ");
do {
system_of_measurement = in.nextInt();
in.nextLine();
if (system_of_measurement<1||system_of_measurement>2)
System.out.print("Wrong value. Please, enter it again.: ");
} while (system_of_measurement<1||system_of_measurement>2);
if(system_of_measurement==1)
{
System.out.println("kg");
healthy_weight=height*height*25;
}
else
{
System.out.println("pounds");
healthy_weight=height*height*25/703;
}
if(healthy_weight>25)
System.out.println("You have to lose weight.");
if(healthy_weight>=18.5&&healthy_weight<=25)
System.out.println("Your weight is considered healthy.");
if(healthy_weight<18.5)
System.out.println("You have to win weight.");
System.out.println("Person name: " + person_name);
System.out.println("Value of healthy weight: " + healthy_weight);
}
}