CPSC 120 Postlab 2: Ideal Weight
Write a program to compute the "ideal" weight for both
males and females. According to one study, the ideal weight for
a female is 100 pounds plus 5 pounds for each inch in height
over 5 feet. For example, the ideal weight for a female who is
5'3" would be 100 + 15 = 115 pounds.
For a male the ideal weight is 106 pounds plus
6 pounds for each inch in height over 5 feet. For example, the ideal weight
for a male who is 6'2" would be 106 + 14*6 = 190 pounds.
Your program should ask the user to enter his/her height in feet
and inches (both as integers -- so a person 5'3" would enter the
5 and the 3). It should then compute and print both the ideal
weight for a female and the ideal weight for a male. The general
outline of your
program should be as follows:
Plan your program, then type it in,
compile and run it. Be sure to test it on a wide range of heights.
(The formula given does not address heights under 5 feet, but
your program should do something reasonable for this case as well.)
- Declare your variables (think about what variables you need --
you need to input two pieces of information (what?), then you
need some variables for your calculations (see the following
- Get the input (height in feet and inches) from the user
- Compute the total number of inches of height (convert feet and
inches to total inches)
- Compute the ideal weight for a female and the ideal weight
for a male (here you basically convert the "word" description
above to assignment statements)
- Print the answers, nicely labeled and formatted.
Now enhance the program by providing weight ranges instead of a single
Modify your program so that in addition to its current output it prints an okay range for each sex -- the range is from the ideal weight
minus 15% to the ideal weight plus 15%. You may do this by introducing new variables and assignment statements OR directly within your print statements.
What to turn in
Turn in hardcopy of your program and e-mail the .java file to your
instructor @roanoke.edu. Be sure to put cpsc120 post2 in the subject
of your message.