我创建了几个 if else 语句,以及解析一个 double ,然后答案是 double = 每个 else 语句。当我运行程序时,它运行得很好,除了每个答案如果给出......
//Makes a variable for the entered amount
double mercurypf;
double venuspf;
double earthpf;
double marspf;
double jupiterpf;
double saturnpf;
double uranuspf;
double neptunepf;
double plutopf;
// constants
final double mercuryforce = 0.38;
final double venusforce = 0.91;
final double earthforce = 1.00;
final double marsforce = 0.38;
final double jupiterforce = 2.34;
final double saturnforce = 1.06;
final double uranusforce = .92;
final double neptuneforce = 1.19;
final double plutoforce = 0.06;
// Code used to determine which planet RadioButton is checked:
if(mercury.isChecked())
{
mercurypf = mercuryforce * weight;
}
else
{
mercurypf = 0.00;
}
if(venus.isChecked())
{
venuspf = venusforce * weight;
}
else
{
venuspf = 0.00;
}
if(earth.isChecked())
{
earthpf = earthforce * weight;
}
else
{
earthpf = 0.00;
}
if(mars.isChecked())
{
marspf = marsforce * weight;
}
else
{
marspf = 0.00;
}
if(jupiter.isChecked())
{
jupiterpf =jupiterforce * weight;
}
else
{
jupiterpf = 0.00;
}
if(saturn.isChecked())
{
saturnpf = saturnforce * weight;
}
else
{
saturnpf = 0.00;
}
if(uranus.isChecked())
{
uranuspf = uranusforce * weight;
}
else
{
uranuspf = 0.00;
}
if(neptune.isChecked())
{
neptunepf = neptuneforce * weight;
}
else
{
neptunepf = 0.00;
}
if(pluto.isChecked())
{
plutopf = plutoforce * weight;
}
else
{
plutopf = 0.00;
}
//Creates a textview object, assigns the xml r.id, and then changes the text to report the amount.
TextView t = (TextView)findViewById(R.id.ansTextView);
t.setText("Your planetary weight is: " + plutopf + neptunepf + uranuspf + saturnpf + jupiterpf + marspf + earthpf + mercurypf + venuspf);
}
}
答案将是 0.0 0.0 0.0 9.1 0.0 0.0 等等......除了被选中的星球之外的所有东西都剩下 0.0> 我知道这是由于 MY =mercurypf + plutopf ... 有没有办法避免不得不这样做,但仍然返回他们选择的单选按钮的结果?