2016-11-30 12 views
0

Android Studio 2.2.2(MainActivity.java)でプログラムを書く。基本的に、複数の入力、1つのボタン、複数の出力があります。しかし、出力の多くは他の出力の多くにクロスリファレンスされています。私は教授が非プログラミングのクラスで私たちにこれを投げかけたので、私はこのすべてに慣れていません。誰も私のエラーの一部を見ることができますか?私はプロセスが大丈夫だと思っていますが、操作には文字列/浮動小数点/二重の非互換性に関する問題があります。どんな洞察もありがとう!数学演算のためのフロートへの変換

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,etH,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); 
    etH = (EditText)findViewById(R.id.etH); 
    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) { 
     Float B = Float.parseFloat(etB.getText().toString()); 
     Float D = Float.parseFloat(etD.getText().toString()); 
     Float H = Float.parseFloat(etH.getText().toString()); 
     Float As = Float.parseFloat(etAs.getText().toString()); 
     Float Fc = Float.parseFloat(etFc.getText().toString()); 
     Float Fy = Float.parseFloat(etFy.getText().toString()); 
     Float aResult = Float.parseFloat(tvaResult.getText().toString()); 
     Float cResult = Float.parseFloat(tvcResult.getText().toString()); 
     Float etResult = Float.parseFloat(tvetResult.getText().toString()); 
     Float beta1Result = Float.parseFloat(tvbeta1Result.getText().toString()); 
     Float phiResult = Float.parseFloat(tvphiResult.getText().toString()); 
     switch(view.getId()) { 
      case R.id.btnCalc: 
       tvaResult = (Fy * As)/(0.85 * Fc * B); 
       tvcResult = aResult/beta1Result; 
       tvetResult = ((D - cResult)/(cResult)) * 0.003; 
       if (Fc <= 4000) { 
        beta1Result = 0.85; 
       } else if (4000 < Fc <= 8000) { 
        beta1Result= ((0.85)-(0.05 * ((Fc - 4000)/(1000)))); 
       } else { 
        beta1Result= 0.65; 
       } 
       if (etResult >= 0.005) { 
        tvphiResult= 0.9; 
       } else if (0.002 <= etResult < 0.005) { 
        tvphiResult= 0.65 + ((etResult - 0.002) * ((0.25)/(0.005 - 0.002))); 
       } else { 
        tvphiResult= 0.00 
       } 
       tvMnResult= (Fy * As) * (etD - (aResult/2)); 
       tvphiMnResult= phiResult * tvMnResult 
     }} 
}} 
+0

誰でも私の間違いのいくつかを見ることができますか?_いいえ、何も見ません。いくつかのコードを提供してください。 See [ask]。歓迎SO – AxelH

+0

AxelH:コードを追加し、質問を書くのが簡単で、コードを追加しました。 これは文字通り、コード化する必要があるのは初めてのことなので、多分エラーがあることは知っています。私は誰もが私のためにこれのすべてを行うことを期待していない、任意の助けを感謝します。 –

+0

あなたがエラーの多くを言って以来、theresはコードのどの行に兆候がなければならないのですか? – MVCNoob

答えて

0

簡潔にするために、各変数のタイプを保持する必要があります。例えばここで

tvaResult = (Fy * As)/(0.85 * Fc * B); 

あなたは、これは当然のことながら行うことができない、TextViewのインスタンスにFloat値を入れしようとしている

TextView = (Float * Float)/(Double * Float * Float) 
TextView = Double // Not possible 

を持っています。あなたは、これはbasicly常に行って同じ間違いです

を印刷するテキストを変更するには

tvaResult.setText((Fy * As)/(0.85 * Fc * B) + ""); // Need to be convert into String 

:しかし、あなたは本当にのTextViewのテキストを更新し、そのような方法にのTextViewのsetText(String)を使用したいですTextViewのテキストを変更する必要があります。インスタンス自体を変更しようとしていません。

+0

ありがとうございます!それがその1行に役立った。私は他の人にも同様のフォーマットとロジックに従おうとします! –

+0

ちょうどメモ、浮動計算に注意してください、あなたは驚きかもしれません... – AxelH

関連する問題