SHARE
SPREAD
HELP

The Tradition of Sharing

Help your friends and juniors by posting answers to the questions that you know. Also post questions that are not available.


To start with, Sr2Jr’s first step is to reduce the expenses related to education. To achieve this goal Sr2Jr organized the textbook’s question and answers. Sr2Jr is community based and need your support to fill the question and answers. The question and answers posted will be available free of cost to all.

 

#
Authors:
Walter Savitch ,kenrick Mock
Chapter:
Getting Started
Exercise:
Programming Projects
Question:9 | ISBN:9780132830317 | Edition: 5

Question

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.


TextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbook

Answer

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

 

0 0

Discussions

sinaaa

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.