Lab 3: Generating the BMI Table
The goal of this lab is to write a code BMITable.java that produces a table of BMI (the Body-Mass Index). The body-mass index of a person is determined by the height and weight of the person, given by the formula:
703.0 * (the height in inches) / (the weigh in pounds)-squared.
Our goal is to write a code that produces a table that shows the BMI value for a range of height and a range of weight.
The lab task consists of two parts. Part 1 is worth ten points and part 2 is worth two extra points. In Part 1, the size parameters for the table will be fixed while in Part 2, the size parameters will be entered by the user.
Part 1: Fixed-size BMI Table
We will use a double loop for the table generation. The rows of the table are the weight, which ranges from 260 pounds down to 80 pounds with the step-width of 5 (that is, the values are 260, 255, 250, …). The columns of the table are the height, which ranges from 56 inches to 76 inches with the step-width of 2 (that is, the values are 56, 58, 60, …). We use the formula 703.0 * weight / (height * height) for calculating the value. We will print each BMI value using System.out.printf(“%5.1f”, xxx) to print xxx in five chater spaces with one digit below the decimal point.
template
// compute and pring a BMi Table
public class BMITable {
//—————————————-
// printout the separator
//—————————————-
public static void theSeparator() {
System.out.print(“——-+”);
for (int position = 1; position <= 55; position ++) {
System.out.print("-");
}
System.out.println();
}
//----------------------------------------
// printout the header
//----------------------------------------
public static void theHeader() {
//----------------------------------------
// ******** NEED CODE HERE FOR THE FIRST LINE OF HEADER
//----------------------------------------
System.out.print("(lbs.) |");
//----------------------------------------
// ******** NEED CODE HERE FOR THE REST ***********
//----------------------------------------
}
//----------------------------------------
// compute and print out the table
//----------------------------------------
public static void theTable() {
//----------------------------------------
// ******** NEED CODE HERE ***********
//----------------------------------------
}
//----------------------------------------
// main
//----------------------------------------
public static void main(String[] args) {
theSeparator();
theHeader();
theSeparator();
theTable();
theSeparator();
}
}