I'm working on an assignment where I have to create an "ideal weight" calculator (kinda like a BMI calculator). The user is supposed to input their height, name, and the system of measure they wish to receive their answer in.
ie; system of measure = (M)etric or (I)mperial where the user input either a 'm' or an 'i'. This means that their input of height has to corresponding to their chosen unit.
ie; height= 1.5 meters or 59 inches (except they don't write the units, just the numbers).
I've tried to fix any syntax errors that may be present, and currently there are no longer any errors, but still, my GUI won't output anything when I click the calculate button. I'm not sure what is wrong with it. Please help me. This summative assignment is due tonight and I'm unable to run it through successfully:(((
String strName, strSystem;
strName=this.jTextField1.getText();
strSystem=this.jTextField2.getText().toUpperCase();
if(strSystem.equals("M"))
{
double height = Double.parseDouble(lblHeight.getText());
double weight = height*height*25;
this.lblOutput.setText(strName + "'s Ideal Weight is:" + weight
+ "Kg");
}
else if (strSystem.equals("I"))
{
double height = Double.parseDouble(lblHeight.getText());
double weight = (height*height*25)/703;
this.lblOutput.setText(strName+ "'s Ideal Weight is:" + weight
+ "lb");
}
this.lblOutput.setText("" + strSystem);
}
The GUI is supposed to use the following formulas to calculate their "ideal weight" in the unit they have selected in the "system of measure".
*FORMULAS:
Metric:Weight (kg) = height (metres) × height (metres) × 25
Imperial: Weight (pounds) = height (inches) × height (inches) × 25 ÷ 703*
The GUI is supposed to look somewhat like this:
*Name: Eva
System of measure [(M)etric or (I)mperial]: M
Height [(M)eters or (I)nches]: 1.5
OUTPUT: Eva's ideal weight is ___kg.*
Aucun commentaire:
Enregistrer un commentaire