Question
// This program computes two people's body mass index (BMI) and // compares them. The code uses Scanner for input, and parameters/returns. import java.util.*; //
// This program computes two people's body mass index (BMI) and
// compares them. The code uses Scanner for input, and parameters/returns.
import java.util.*; // so that I can use Scanner
public class BMI {
public static void main(String[] args) {
introduction();
Scanner console = new Scanner(System.in);
double bmi1 = person(console);
double bmi2 = person(console);
// report overall results
report(1, bmi1);
report(2, bmi2);
System.out.println("Difference = " + Math.abs(bmi1 - bmi2));
}
// prints a welcome message explaining the program
public static void introduction() {
System.out.println("This program reads data for two people and");
System.out.println("computes their body mass index (BMI).");
System.out.println();
}
// reads information for one person, computes their BMI, and returns it
public static double person(Scanner console) {
System.out.println("Enter next person's information:");
System.out.print("height (in inches)? ");
double height = console.nextDouble();
System.out.print("weight (in pounds)? ");
double weight = console.nextDouble();
System.out.println();
double bodyMass = bmi(height, weight);
return bodyMass;
}
// Computes/returns a person's BMI based on their height and weight.
public static double bmi(double height, double weight) {
return (weight * 703 / height / height);
}
// Outputs information about a person's BMI and weight status.
public static void report(int number, double bmi) {
System.out.println("Person " + number + " BMI = " + bmi);
if (bmi < 18.5) {
System.out.println("underweight");
} else if (bmi < 25) {
System.out.println("normal");
} else if (bmi < 30) {
System.out.println("overweight");
} else {
System.out.println("obese");
}
}
}
Question: Using Nested if/else modify the BMI program located above.Add two more persons and calculate the difference of bmi3 and bmi4.Upload the source code and the screenshot of the running program.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started