我正在创建一个BMI理想体重计算器,提示用户在文本框中输入数据或信息,例如他们的姓名,身高,体重(体重可以是公制,也就是公斤或英制),高度可以是米或英尺。我也使用一个单选按钮,两个不同的单位来区分性别(男性或女性),因为男性和女性有不同的BMI。我应该参考的信息和公式在下面的照片中,但我的问题是到目前为止,当我编码时,我只是测试男性单选按钮,因为我完成了它,没有输出到我的jLabel aka lblOutput ... 以下是我想要的简要说明: 1)提示用户点击性别(radiobutton) 2)然后需要用户填写信息 3)假设输出BMI并告诉人们它是否正常,体重不足等。 这是代码(到目前为止我所拥有的):
String name = txt1.getText();
double Metric = Double.parseDouble(txt2.getText());
double Imperial = Double.parseDouble(txt2.getText());
double metres = Double.parseDouble(txt3.getText());
double inches = Double.parseDouble(txt4.getText());
double kgs = Double.parseDouble(txt5.getText());
double pounds = Double.parseDouble(txt5.getText());
double weight;
double weight2;
int m = 1;
int i =2;
int me =3;
int in=4;
if (rdbMale.isSelected()) {
if (Metric==m) {
//inches = System.null(); //need to learn how to make it null or dissapear if user inputs for metric instead of imperial
weight = metres/Math.pow(kgs, 2);
lblOutput.setText("Your name is " + name + " and your ideal weight in kgs is " + String.format("%.2f", weight));
}
} else if (Imperial==i) {
weight2 = inches/Math.pow(pounds, 2)*703;
lblOutput.setText("Your name is " + name + " and your ideal weight in pounds is " + String.format("%.2f", weight2));
}
// some codes are unneccessary like the int me, or the int in i used them so i can distinguish between which one the user wants to chose from either 3 for metres or 4 for inches, pls ignore that
//I basically just want this to work and I don't know how to get it to work