Hi I am just starting to learn about java.I am trying to calculate BMI of an individual using the JOptionPane.showInputDialog method who I am asking to enter 4 things first name,last name,height in inches and weight in pounds. I want to show the BMI using JOptionPane.showMessageDialog method showing their full name and BMI.What am I doing wrong ?

import javax.swing.JOptionPane;

public class P1 {

    public static void main(String[] args) {

        String FirstName = JOptionPane.showInputDialog("Enter your First name");
        String LastName = JOptionPane.showInputDialog("Enter your Last name");
        double height = JOptionPane.showInputDialog("Enter your height in inches");
        int inches = Integer.parseInt(height);
        int metre= inches*0.0254;

        double weight =JOptionPane.showInputDialog("Enter your weight in pounds");
        int pounds = Integer.parseInt(weight);
        int kilo= pounds/2.2;

        String response=
                "kilo"*sqrt"metre" +"FirstName"+"Lastname"

        JOptionPane.showMessageDialog(null, response);
    }

}

I want to show the BMI using JOptionPane.showMessageDialog method showing their full name and BMI.What am I doing wrong ?

Can you explain what the program does that is "wrong"?

Try this:

        double results = kilo * sqrt(metre);
        String response= results + " " + FirstName + " " + Lastname;

Hi by wrong I mean this is the error when i try to run my java application
Type mismatch: cannot convert from String to double

The method parseInt(String) in the type Integer is not applicable for the arguments
(double)
Type mismatch: cannot convert from double to int
The method sqrt(int) is undefined for the type P1
at P1.main

The posted error messages left off the source code line numbers.

parseInt(String) in the type Integer is not applicable for the arguments (double)

The parseInt() method requires a String for its arg, not a double. What data are you trying to convert to an int?

The method sqrt(int) is undefined

The compiler can not find a definition for the method: sqrt()? What class is it defined in?
Where is it defined?

Type mismatch: cannot convert from double to int

What line did this error happen on?

Type mismatch: cannot convert from double to int
this happened on line 11 and line 15

The method sqrt(int) is undefined
I fixed that using Math.sqrt

cannot convert from string to double
This happened on line 9

parseInt(String) in the type Integer is not applicable for the arguments (double)
I am trying to convert height and weight into an int for my BMI

I have got most of my coding sorted.But i still cant figure out how to make the user enter their height and weight without 0 and 0 because if i dont put eg double inches=0; then it says local variable is not initialized I want the user to enter any number for weight and height and still calculate.

import javax.swing.JOptionPane;



public class P1 {

    public static void main(String[] args) {

        double inches=0;
        double pounds=0;

        String FirstName = JOptionPane.showInputDialog("Enter your First name");
        String LastName = JOptionPane.showInputDialog("Enter your Last name");

        String height = JOptionPane.showInputDialog("Enter your height in inches");
        double metre= inches*0.0254;

        String weight =JOptionPane.showInputDialog("Enter your weight in pounds");
        double kilo= pounds/2.2;

        double results = kilo * Math.sqrt(metre);
        String response= results + " " + FirstName + " " + LastName;

        JOptionPane.showMessageDialog(null, response);
    }

}

What do you do with the height and weight values that the user enters in response to the JOptionPane prompts? Should the String that the user entered be converted to a numeric value so you can do arithmetic with it to compute the values you want to display?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.