Site Search

# CS 110: Program 1

## Student Learning Objectives

• Demonstrate test-driven development and the ability to hand-calculate test cases
• Demonstrate the use of jGRASP to type in, compile, and execute a simple Java program
• Demonstrate the use formatting style to produce readable programs

## 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 is calculated based on a person's weight and height. The math formula for calculating BMI is shown at right

Simple BMI categories include

• Underweight when BMI is less than `18.5`
• Normal weight when BMI is between `18.5` and `25`
• Overweight when BMI is between `25` and `30`
• Too Muscular (Obese) when BMI is `30` or greater

## 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

## Sample Output

```How much do you weigh (in pounds)? `152.5`
How tall are you (in inches)? `71.3`
```

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

• Your hand-written values entered in the BMI Test Cases table contained on the CS 110 Program 1 Grading Sheet (PDF)
• Use a calculator to hand-calculate the four BMI values for the weight and height values provided in the test cases
• Write your your program's output values for BMI for the four test cases
• Be sure your project is saved in your `U:\programs\program1\` folder on the computer science network.
• Use "My Computer" to check this.
• Ask your TA at the start of Lab if you need help with this
• You do not need to submit a program printout; your solution will be checked online from your computer account
• The assignment is due at the start of Lab 2.
• If you are unable to finish in time, you may turn in what you have done to receive partial credit for the assignment.
• You are allowed to drop one program assignment score for the quarter

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

• 10 points - Output Correctness
• The program calculates and displays the correct calculated values for Body Mass Index with different user input (-2 per test case, 8 points possible)
• The prompts and output for the program is correctly worded and formatted according to the sample output shown above
• Duplicate the sample output exactly, do not make up your own words or formatting (-1 per problem, 2 points possible)
• 4 points - Comments and Alignment
• Include single-line Java comments beginning with `//` to explain what your program is doing (-1 point per missing comment, 3 points possible)
• Skip one blank line before every single-line comment (1 point possible)
• Use jGRASP's Generate CSD to properly indent and align your code
• 2 points - Identifier Names
• Use meaningful variable names for all Java variables used (-1 point per problem, 2 points possible)
• Variable identifier names should use lower camel casing (begin with a lower case letter, and each subsequent word should start with an upper-case letter)
• Avoid the use of abbreviations in choosing variable names
• 4 points - Creation of Assignment Folder, File, and Test Cases
• Folder `U:\programs\program1\` created correctly on your network CS 110 account (1 point possible)
• Java program file saved as `U:\programs\program1\BodyMassIndex.java` (1 point possible)
• Test case table hand-calculated values are correct (-1 per incorrect calculation, 2 point possible)

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