这是一个计算器程序,其中有几个输入用于创建多个输出。我正在编写的应用程序上的单个按钮运行所有计算然后给出输出。
我在public void onClick
下的行上得到一个一致的“警告”警告是:Variable 'aResult' initializer 'Double.parseDouble(tvaResult.getText().toString())'
是多余的
package com.example.ericallenbellville.rcbeamdesign;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
private Button btnCalc;
private TextView tvaResult;
private TextView tvcResult;
private TextView tvetResult;
private TextView tvphiResult;
private TextView tvMnResult;
private TextView tvphiMnResult;
private TextView tvbeta1Result;
private EditText etB,etD,etAs,etFc,etFy;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
init();
}
private void init() {
btnCalc = (Button)findViewById(R.id.btnCalc);
etB = (EditText)findViewById(R.id.etB);
etD = (EditText)findViewById(R.id.etD);
etAs = (EditText)findViewById(R.id.etAs);
etFc = (EditText)findViewById(R.id.etFc);
etFy = (EditText)findViewById(R.id.etFy);
tvaResult = (TextView)findViewById(R.id.tvaResult);
tvcResult = (TextView)findViewById(R.id.tvcResult);
tvetResult = (TextView)findViewById(R.id.tvetResult);
tvphiResult = (TextView)findViewById(R.id.tvphiResult);
tvMnResult = (TextView)findViewById(R.id.tvMnResult);
tvphiMnResult = (TextView)findViewById(R.id.tvphiMnResult);
tvbeta1Result = (TextView)findViewById(R.id.tvbeta1Result);
btnCalc.setOnClickListener(this);
}
@Override
public void onClick(View view) {
btnCalc = (Button)findViewById(R.id.btnCalc);
Double B = Double.parseDouble(etB.getText().toString());
Double D = Double.parseDouble(etD.getText().toString());
Double As = Double.parseDouble(etAs.getText().toString());
Double Fc = Double.parseDouble(etFc.getText().toString());
Double Fy = Double.parseDouble(etFy.getText().toString());
Double aResult = Double.parseDouble(tvaResult.getText().toString());
Double cResult = Double.parseDouble(tvcResult.getText().toString());
Double etResult = Double.parseDouble(tvetResult.getText().toString());
Double beta1Result = Double.parseDouble(tvbeta1Result.getText().toString());
Double phiResult = Double.parseDouble(tvphiResult.getText().toString());
Double MnResult = Double.parseDouble(tvMnResult.getText().toString());
Double phiMnResult = Double.parseDouble(tvphiMnResult.getText().toString());
switch(view.getId() ) {
case R.id.btnCalc:
if (Fc <= 4000) {
beta1Result = (0.85);
} else if (4000 < Fc && Fc <= 8000) {
beta1Result = ((0.85)-(0.05 * ((Fc - 4000) / (1000))));
} else {
beta1Result = 0.65;
}
aResult = ((Fy * As) / (0.85 * Fc * B));
cResult = (aResult / beta1Result);
etResult = (((D - cResult) / (cResult)) * 0.003);
if (etResult >= 0.005) {
phiResult = (0.9);
} else if (0.002 <= etResult && etResult < 0.005) {
phiResult = (0.65 + (etResult - 0.002) * 0.25 / (0.005 - 0.002));
} else {
phiResult = (0.00);
}
MnResult = (((Fy * As) * (D - (aResult / 2.0))));
phiMnResult = phiResult * MnResult;
tvaResult.setText(String.valueOf(aResult));
tvcResult.setText(String.valueOf(cResult));
tvetResult.setText(String.valueOf(etResult));
tvphiResult.setText(String.valueOf(phiResult));
tvMnResult.setText(String.valueOf(MnResult));
tvphiMnResult.setText(String.valueOf(phiMnResult));
}}
}