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();
}
}
Delivering a high-quality product at a reasonable price is not enough anymore.
That’s why we have developed 5 beneficial guarantees that will make your experience with our service enjoyable, easy, and safe.
You have to be 100% sure of the quality of your product to give a money-back guarantee. This describes us perfectly. Make sure that this guarantee is totally transparent.
Read moreEach paper is composed from scratch, according to your instructions. It is then checked by our plagiarism-detection software. There is no gap where plagiarism could squeeze in.
Read moreThanks to our free revisions, there is no way for you to be unsatisfied. We will work on your paper until you are completely happy with the result.
Read moreYour email is safe, as we store it according to international data protection rules. Your bank details are secure, as we use only reliable payment systems.
Read moreBy sending us your money, you buy the service we provide. Check out our terms and conditions if you prefer business talks to be laid out in official language.
Read more