Write a Java program that performs these operations Prompt t

Write a Java program that performs these operations:

Prompt the user to enter a low height in feet (an integer).

Prompt the user to enter a high height in feet (an integer).

Prompt the user to enter a low weight in pounds (an integer).

Prompt the user to enter a high weight in pounds (an integer).

Print a table of Body Mass Index (BMI) for the heights and weights entered, ranging from the low height to the high height (inclusive), at increments of 3 inches, and for each height, from the low weight to the high weight (inclusive), in increments of 10 pounds.

Each row of the table lists the height in feet and inches (two integers separated by a space), followed by 4 spaces, followed by the weight (an integer), followed by 9 spaces, then the BMI to four decimal places (a float), followed by 9 spaces, then whether the user is overweight (BMI > 25), or not overweight (BMI < 25).

Solution


// java code BMI calculator

import java.util.Scanner;
public class BMI
{
public static void main(String[] args)
{
Scanner scan = new Scanner(System.in);
  
double bmi;
int lowheight, highheight;
int lowweight, highweight;
  
double POUND_TO_KG = 0.45359237;
double FOOT_TO_METER = 0.3048;
double FOOT_TO_INCH = 12;
  
System.out.println(\"Enter a low height in feet(an integer): \");
lowheight = scan.nextInt();
System.out.println(\"Enter a high height in feet(an integer): \");
highheight = scan.nextInt();
System.out.println(\"Enter a low height in pounds(an integer): \");
lowweight = scan.nextInt();
System.out.println(\"Enter a high weight in pounds(an integer): \");
highweight = scan.nextInt();


int ht = lowheight;
int wt = lowweight;

System.out.println();
while(ht <= highheight && wt <= highweight )
{
double weight = wt * POUND_TO_KG; // convert weight from pounds to kilograms
double height = ht * FOOT_TO_METER; // covert height from inches to meters
bmi = weight/(Math.pow(height, 2));

bmi = (double)Math.round(bmi * 10000d) / 10000d;

if(bmi > 25)
System.out.println(ht + \" \" + 12*ht + \" \" + wt + \" \" + bmi + \" \" + \"overweight\ \");
else
System.out.println(ht + \" \" + 12*ht + \" \" + wt + \" \" + bmi + \" \" + \"not overweight\ \");

ht=ht+3;
wt=wt+10;
}
  
}
}

/*
output:

Enter a low height in feet(an integer):
2
Enter a high height in feet(an integer):
15
Enter a low height in pounds(an integer):
100
Enter a high weight in pounds(an integer):
200


2 24 100 122.0607 overweight

5 60 110 21.4827 not overweight

8 96 120 9.1546 not overweight

11 132 130 5.2456 not overweight

14 168 140 3.4874 not overweight


*/

Write a Java program that performs these operations: Prompt the user to enter a low height in feet (an integer). Prompt the user to enter a high height in feet
Write a Java program that performs these operations: Prompt the user to enter a low height in feet (an integer). Prompt the user to enter a high height in feet

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site