PIC20A
HW 1: Are you overweight?
Assignment
This is a very easy Homework.
You are going to write a program to calculate Body Mass Index. Then tell the user if he/she is overweight or not.
Body Mass Index is given by
Your Weight (in pounds) x 704.5 divided by (Your Height (in inches) x Your Height (in inches))
Here is a table from this link.
Adults BMI: |
Women |
Men |
underweight |
< 19.1 |
< 20.7 |
in normal range |
19.1 - 25.8 |
20.7 - 26.4 |
marginally overweight |
25.8 - 27.3 |
26.4 - 27.8 |
overweight |
27.3 - 32.3 |
27.8 - 31.1 |
very overweight or obese |
> 32.3 |
> 31.1 |
Sample Program
You can download the program
BMI.class
on your computer. After you download it, open a DOS prompt, use cd
to change
to the correct folder.
Sample Section
java BMI gender height(in inches) weight(in pounds)
gives the body mass index of the given height and weight.
gender
is a character (m, M, f, F).
height
and weight
are double
s.
You can assume the user uses the correct syntax. i.e. you don't have to do error checking.
java BMI m 78 200
Your Body Mass Index is 23.159105851413543
You have a healthy weight.
java BMI f 60 88
Your Body Mass Index is 17.22111111111111
You are underweight.
java BMI F 67 166.5
Your Body Mass Index is 26.130374248162173
You are marginally overweight.
java BMI M 85 320
Your Body Mass Index is 31.202768166089964
You are very overweight.
java BMI m 72 220
Your Body Mass Index is 29.897762345679013
You are overweight.
|
What to submit
Call your source code file BMI.java.
Put this file in your submit folder.
Do not place this file inside another folder within your submit folder.
Remark
- All source code submitted must contain the following information at the beginning of each file:
- Your full name
- Your student ID number
- Your PIC login ID
- Your e-mail address
- Your discussion section number and TA's name
- The assignment number and description
- Honesty pledge
Properly formatted, this information should appear as follows:(Please change the Name, Student ID, PIC ID, E-mail, Discussion
/** Name: Charles Li
* Student ID : 000 000 000
* PIC ID: ccli
* E-mail: ccli@math.ucla.edu
* Discussion: 1A, Baber
* Assignment: hw1
*
* I, Charles Li, pledge that this is my own independent work, which
* conforms to the guidelines of academic honesty as described in the course
* syllabus.
*
*/
- If you develop your program on your home computer, make sure it compiles and runs on the lab machines before you turn it in.
- Please use consistent and neat indenting in all your programs.
- Please comment your program.
Solution
BMI.java