Help with Java

No replies
toughcookieone
Offline
Last seen: 9 years 20 weeks ago
Joined: 2010-10-06
bOt Points: 54

Hello everyone! I am extremely new to this while Java Programming thing, and I was needing some help. I am supposed to get the program to ask for height and weight with input, then calculate the BMI. I got all of that in, and I even got it to display the correct BMI. However, I am also supposed to have the program display wether the person is overweight, underweight etc with the value for the BMI. I cant seem to figure out how to go about that. I am not sure if I need to use if/else, while, or nothing. Here is my code, if anyone could help me at all! Thanks very much!

import javax.swing.JOptionPane;

public class BMI
{

public static void main(String[] args)
{
//For reading input
String inputString;
double weight;
double height;
double bmi;

//Ask for weight
inputString =
JOptionPane.showInputDialog("Enter your weight in pounds");
weight= Integer.parseInt(inputString.trim());

//Ask for test height
inputString =
JOptionPane.showInputDialog("Enter your height in inches");
height= Integer.parseInt(inputString.trim());

//Calculate the BMI.
bmi = weight*703/(height*height);

if (bmi < 18.5)
//Display the result
JOptionPane.showMessageDialog(null,"Your BMI is "
+ bmi
+ "\n You are underweight!");

if (bmi >= 18.5 || < 25.0)
//Display the result
JOptionPane.showMessageDialog(null,"Your BMI is "
+ bmi
+ "\n You are at your optimal weight!");

if (bmi >= 25.0 || <30.0);
//Display the result
JOptionPane.showMessageDialog(null,"Your BMI is "
+ bmi
+ "\n You are overweight!");

if (bmi > 30.0)
//Display the result
JOptionPane.showMessageDialog(null,"Your BMI is "
+ bmi
+ "\n You are obese!");

//End the program.
System.exit(0);
}

}