Where weight is the person’s weight in grams and height is their height in centimeters. If the result of this calculation is less that 20, then the person is medically underweight. If the result is greater than 30 then the person is medically overweight. Write a program to calculate whether a given person is underweight or overweight.

import javax.swing.JOptionPane;
public class Bmi {

    public static void main(String[] args) {

    //declare variables

    int height;
    int weight;
    String accept;
    double bmi;
   //Accept the height and weight from user
    accept = JOptionPane.ShowInputDialog("Enter Weight");
    weight = Integer.ParseInt(accept);
    accept = JOptionPane.ShowInputDialog("Enter Height");
    height = Integer.ParseInt(accept);

   //Caculate the BMI with giving formula
   bmi = (10 * weight) / (height * height);

   // Do If statement to make output
   if(bmi < 20)
      JOptionPane.ShowMessageDialog(null,"User is Underweight");
   else if (bmi > 30)
     JOptionPane.ShowMessageDialog(null,"User is Overweight");
    else
     JOptionPane.ShowMessageDialog(null,"User Has a Good Weight+");

    	System.exit(0);
    }
}

its keep showing cannot find symbol method showInputDialog(java.lang.string) and
cannot find symbol method parseInt(java.lang.string

Edited 5 Years Ago by Ezzaral: Added code tags. Please use them to format any code that you post.

Those sound like compiler errors.

cannot find symbol method showInputDialog(java.lang.string)

The text of the error message you posted does NOT match your code. Case is important in java

cannot find symbol method parseInt(java.lang.string

Same problem here.

When you post error messages it is VERY IMPORTANT that you copy and paste them as they came from the compiler vs typing in something that is similar.

Edited 5 Years Ago by NormR1: n/a

Java names are case-sensitive. Method names in the API begin with a lower case letter. Check your method names for capital vs lower case against the API reference.

its still the same...can you run it on your laptop..thanks and checked it for me...

yep, your code runs just fine, you just need to use the correct upper and lower cases, as was suggested earlier.

After I fix the spelling errors it runs fine for me. I don't get any errors.

Next time please use the code tags

Your code with fixed cases:

import javax.swing.JOptionPane;



public class Bmi {

	public static void main(String[] args) {

		//declare variables

		int height;
		int weight;
		String accept;
		double bmi;
		//Accept the height and weight from user
		accept = JOptionPane.showInputDialog("Enter Weight");
		weight = Integer.parseInt(accept);
		accept = JOptionPane.showInputDialog("Enter Height");
		height = Integer.parseInt(accept);

		//Caculate the BMI with giving formula
		bmi = (10 * weight) / (height * height);

		// Do If statement to make output
		if(bmi < 20)
			JOptionPane.showMessageDialog(null,"User is Underweight");
		else if (bmi > 30)
			JOptionPane.showMessageDialog(null,"User is Overweight");
		else
			JOptionPane.showMessageDialog(null,"User Has a Good Weight+");

		System.exit(0);
	}
}
Comments
Why do the OPs homework?

@andersonelnino DO NOT create multiple posts with same question, just because you are not getting answer fast enough. This is not 24/7 support for lazy students

For these wishing to follow this "enlightening" discussion can do so here.

Thread closed.

This article has been dead for over six months. Start a new discussion instead.