i have to create a Weight application that prompts the user for their gender (male or female) and their height and then determines their ideal body weight. The following formula is used to approximate ideal body weight:
men: Ideal Body Weight (in kilograms) = 60+ 2.3 kg per inch over 5 feet.
women: Ideal Body Weight (in kilograms) = 55.5 + 2.3 kg per inch over 5 feet.
The answer should be displayed in both kilograms and pounds. The following formula is used to convert kilograms to pounds:
pounds = kilograms * 2.2

this is what i have so far. i don't know what to do next. Please fix and give me advises upon completing the application

public class Weight
  {
  public static void main (String[]args)
  {
     Scanner input = new Scanner(System.in);
    int gender;
     int male = 1;
     int female = 2;
	 int menweight = 60; 
		double womenweight = 55.5;
		int height;
    System.out.print("What is your gender ? ( Press 1 = male and 2 = female ");
    int gender = input.nextInt() ;
      System.out.print("What is your height?");
    int height = input.nextInt() ;
     
     
     if ( gender = male ) 
        height =
  }
}

Recommended Answers

All 5 Replies

if ( gender = male )

This is an assignment statement (=) not an equality test (==).

i don't know what to do next.

What have you written code for and what do you need next?

Think of algorithm and methods you may need before implementing your task. I'd suggest this skeleton for your program:

public class Weight
{
    private static final double WOMANWEIGHT = 55.5;
    private static final double MANWEIGHT = 60;
    private static final int MALE = 1;
    private static final int FEMALE = 2;

    public double getMansIdealWeight(double height)
    {
        //insert code that calculates womans ideal weight 
        //and put that expression in brackets instead of 0
        return 0;
    }
    public double getWomansIdealWeight(double height)
    {
        //insert code that calculates mans ideal weight
        //and put that expression in brackets instead of 0
        return 0;
    }

    public double getPounds(double kilograms)
    {
        //insert code to get Pounds when you have kilograms
        //and put that expression in brackets instead of 0
        return 0;
    }

    public static void main(String args[])
    {
        Scanner input = new Scanner(System.in);
        System.out.println("What is your gender ? ( Press 1 = male and 2 = female )");
        int gender = input.nextInt();
        System.out.println("What is your height ?");
        double height = input.nextDouble();

        if (gender == MALE)
        {
            //code to run if its a man
        }

        if (gender == FEMALE)
        {
            //code to run if its a woman
        }
        
        //code to run if its neither a man nor a woman
    }   
}
private static final double WOMANWEIGHT = 55.5;
    private static final double MANWEIGHT = 60;
    private static final int MALE = 1;
    private static final int FEMALE = 2;
 
    public double getMansIdealWeight(double height)

i havent learned these stuff yet

Don't worry about the private static or final for now. Later you'll see why they could be important. It will work without them.

private static final double WOMANWEIGHT = 55.5;
    private static final double MANWEIGHT = 60;
    private static final int MALE = 1;
    private static final int FEMALE = 2;
 
    public double getMansIdealWeight(double height)

i havent learned these stuff yet

Thats's right, you don't need to worry about it. You can just have them as simple identifiers in your main as you did before:

public static void main(String args[])
{
    double WOMANWEIGHT = 55.5;
    double MANWEIGHT = 60;
    int FEMALE = 2;
    int MALE = 1;
    //...
}
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.