lundi 21 septembre 2015

JAVA if Statement works and doesn't work at the same time

The problem is my if Statement. The second if works as designed, it prints out what I asked, but the first one does not even though they are formatted the same way, and defaults to the else statement. I just want to know what I did wrong.

The First if

     if(systemChoice.equals("M")){
        weight = height * height * 25;
        outputLabel.setText(name + ", your ideal weight is " + weight + " kgs.");

The Second if

    if(systemChoice.equals("I")){
        weight = height * height * 25 / 703;
        outputLabel.setText(name + " , your ideal weight is " + weight + " lbs");
    }

And here is the whole program in context if necessary

     String name, systemChoice;
    double height, weight;

    name = nameInput.getText();
    systemChoice = systemInput.getText();
    height = Double.parseDouble(heightInput.getText());

    /*Calculates your ideal weight 
    *based on a bmi formula in 
    *your preferred system of measurement
    *Imperial or Metric
    */
    if(systemChoice.equals("M")){
        weight = height * height * 25;
        outputLabel.setText(name + ", your ideal weight is " + weight + " kgs.");
    }
    if(systemChoice.equals("I")){
        weight = height * height * 25 / 703;
        outputLabel.setText(name + " , your ideal weight is " + weight + " lbs");
    }
    else{
        outputLabel.setText("Error. Check your System input and try again.");
    }
}          

Aucun commentaire:

Enregistrer un commentaire