Site Navigation

Site Search

CS 110: Program 1

Student Learning Objectives

Introduction

Body mass index (BMI) is a measure of body fat based on height and weight that applies to adult men and women. BMI can be used to indicate if you are overweight, obese, underweight or normal.

Women tend to believe they look their best at BMI values between 20 to 22 and men are usually satisfied with a BMI of 23 to 25.

If your BMI is 30 or more, that's not good. However, the simple BMI calculation tends to overestimate BMI in people who are muscular or athletic. Therefore, if your BMI score seems too high, you're not too fat, your just too athletic.

BMI formula

BMI is calculated based on a person's weight and height. The math formula for calculating BMI is shown at right

Simple BMI categories include

Program Assignment

  1. Hand-calculate the BMI for the four test cases contained on the CS 110 Program 1 Grading Sheet (PDF), given a person's weight and height.
    • This hand-calculations are part of your programming score, so do not skip this step
BMI Test Cases
Weight (lbs.)Height (inches)Hand-Calculated BMIYour Program's BMI Output
125.555.1  
150.067  
13572.3  
19064  
  1. Create a new Java file named BodyMassIndex.java saved in folder U:\programs\program1
    • Note: if you prefer to complete the program at home, you must copy your BodyMassIndex.java file to your CS 110 account's U:\programs\program1 folder to receive a score on the assignment
  2. Write the Java program that
    • Declares variables used in the program
    • Creates a Scanner object
    • Gets the user's weight (in pounds) and height (in inches)
    • Calculates their Body Mass Index (BMI)
    • Displays the results

Tip: This program is very similar to Lab 1's program. Use that program as your guide.

I am expecting most people to use simple multiplication to square height

  1. Compile and Debug your program, eliminating all compiler and logic errors
  2. Compare your program's output to your hand-calculated results to make sure your code is correct

Sample Output

How much do you weigh (in pounds)? 152.5
How tall are you (in inches)? 71.3
Your BMI is 21.088520346441268

Your program's output should match this sample output exactly. Do not make up your own words or formatting.

What to turn in at the start of the next lab

Grading Criteria

20 points possible -- CS 110 Program 1 Grading Sheet (PDF)

Write your full name and account number on CS 110 Program 1 Grading Sheet (PDF) and turn it in at the start of Lab 2