I'm trying to create a simple ideal weight calculator. It accepts two types of inputs, apart from your name - metric and imperial inputs, specifically kg and pounds respectively. In order to designate whether the following field specifies kg or pounds, I have a text input for metric or imperial, where by typing m/M or i/I you pick between metric and imperial.
It looks like this.
Name: ________
(M)etric or (I)mperial: ________
Weight: _________
[[Calculate]]
Here is what the code is:
private void btnInputActionPerformed(java.awt.event.ActionEvent evt) {
//Acquire name string info
String name = this.txtInput_name.getText();
//Aquire system of measurement info
String SOM = this.txtInput_som.getText();
//Acquire height information
String heightInput = this.txtInput_height.getText();
double height = Double.parseDouble(heightInput);
//Set up if statement to deal with I, M, or neither, if user inputs something else
//For imperial (designation i, I):
if ((SOM == "I") || (SOM == "i")) {
//Imperial: Weight (pounds) = height (inches) × height (inches) × 25 ÷ 703
double weightlb = Math.pow(height, 2)*25/703;
this.lblOutput.setText(name + "'s ideal weight is " + weightlb + " pounds.");
}
//For metric (designation m, M):
else if ((SOM == "M") || (SOM == "m")){
//Metric:Weight (kg) = height (metres) × height (metres) × 25
double weightkg = Math.pow(height, 2)*25;
this.lblOutput.setText(name + "'s ideal weight is " + weightkg + "kg.");
}
//For user not inputting any taken designation for metric or imperial as above (e.g. "Celsius", "g", "turkey", etc.)
else {
//Not going to tell them about other ways of designating metric/imperial, label text too long.
this.lblOutput.setText("Please input a valid system of measurement, designation: I or M.");
}
}
The issue is, despite typing in M/m/i/I (one of those at a time!) for Metric or Imperial, it always spits out the result of the else statement - Please input a valid system of measurement...
Have I done something wrong with the conditions of the if/else if statement, or is it something else altogether?