A simple rule to estimate your ideal body weight is to allow 110 pounds for the first 5 feet of height and 5 pounds for each additional inch. Write a program with a variable for the height of a person in feet and another variable for the additional inches. Assume the person is at least 5 feet tall. For example, a person that is 6 feet and 3 inches tall would be represented with a variable that stores the number 6 and another variable that stores the number 3. Based on these values, calculate and output the ideal body weight.
Program:
// IdealBodyWeight.java
public class IdealBodyWeight
{
public static int WEIGHT_FOR_MINIMUM_HEIGHT_IN_POUNDS = 110;
public static int MINIMUM_ALLOW_HEIGHT_IN_FEET = 5;
public static int WEIGHT_PER_ADDITIONAL_INCH_IN_POUNDS = 5;
public static int INCHES_PER_FEET = 12;
public static void main(String[] args)
{
int personHeightInFeet = 6; // should not be less than 5
int personHeightInInches = 3;
double idealBodyWeightInPounds = WEIGHT_FOR_MINIMUM_HEIGHT_IN_POUNDS
+ ((personHeightInFeet - MINIMUM_ALLOW_HEIGHT_IN_FEET)
* INCHES_PER_FEET + personHeightInInches)
* WEIGHT_PER_ADDITIONAL_INCH_IN_POUNDS;
System.out.println("Person height in feet: "
+ personHeightInFeet + "."
+ personHeightInInches);
System.out.println("Ideal Body Weight in pounds: "
+ idealBodyWeightInPounds);
}
}
Output:
Person height in feet: 6.3
Ideal Body Weight in pounds: 185.0
import java.util.Scanner;
public class IdealBodyWeight {
public static int FIRST_5_FEET_WEIGHT = 110;
public static int EACH_ADDITIONAL_INCHES = 5;
public static int CONSTANT_FEET = 5;
public static int INCHES_PER_FEET = 12;
public static double ONE_POUND_IN_KG = 0.4536;
public static void main(String[] args) {
Scanner keyboard = new Scanner(System.in);
System.out.println("Enter your height in feet:");
int heightInFeet = keyboard.nextInt();
System.out.println("Enter remaining inches of your height:");
int inchesOfHeight = keyboard.nextInt();
double idealBodyWeight = (FIRST_5_FEET_WEIGHT +
((heightInFeet - CONSTANT_FEET)*INCHES_PER_FEET + inchesOfHeight)*EACH_ADDITIONAL_INCHES);
System.out.println("Your Ideal Body weight is: " + idealBodyWeight + " pounds");
double idealBodyWeightInKg = idealBodyWeight*ONE_POUND_IN_KG;
System.out.println("Your Ideal Body weight is: " + idealBodyWeightInKg + " Kg");
keyboard.close();
}
}
Post the discussion to improve the above solution.