Question
Hello, I am trying to write a java program that calculates the BMI of up to 100 people. I made a while statement that should
Hello,
I am trying to write a java program that calculates the BMI of up to 100 people. I made a while statement that should repeat if the user responds with "Y" when prompted to, so they can enter in as many people as they want up to 100. However, when I get to the part where the program asks the user if they want to record more people, the program ends immediately. I am not finished with the program but at this point it should repeat the loop, not end. I am not sure where I went wrong here. Here is the code:
{
public static void main(String[] args)
{final int sz = 100; // max # of BMI
String [ ] name = new String [sz];
int [ ] weight = new int [sz];
int [ ] height = new int [sz];
double [ ] BMI = new double[sz];
final double BMIUnder = 18.5;
final double BMINormal = 25.0;
final double BMIOver = 30.0;
final double BMIObese = 30.0;
int normalWeight; // count # of normal weight
int overWeight; // count # of over weight
int obese; // count # of obese people
Scanner k = new Scanner(System.in);
System.out.println("This program calculates BMI for many people. " +
"Step 1 - Enter name, weight & height for every body first " +
"Step 2 - The program calculates all BMI first, it then " +
"Step 3 calculates number of people are under weight " +
"Step 4 calculates number of people are normal weight " +
"Step 5 calculates number of people are over weight " +
"Step 6 calculates number of people are in obesity range");
/** This section allows user enter name, weight, height for up to max number of people & calculate BMI
for each person and store all values into parallel arrays of name, weight, height, BMI */
int i = 0;
while(i { System.out.print("Enter name. "); name [i] = k.nextLine(); System.out.print("Enter weight in pounds. "); weight [i] = k.nextInt(); System.out.print("Enter height in inches. "); height [i] = k.nextInt(); BMI [i] = (weight [i] * 703)/height[i]*height[i]; System.out.println("Enter Y for more, N for no more."); String more = k.nextLine(); if (more.equalsIgnoreCase("Y")) { i++; } else { break; } } } }
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