2012-07-08 104 views
0

好吧,計算錯誤

所以我希望這應該是一個相當簡單的問題,有人在那裏。

該程序工作正常,沒有錯誤,沒有崩潰,所以這是一個良好的開端!

問題是我得到一個不正確的答案。

大約一半時,你應該能夠看到線

CARV= CA*3; tv2.setText(Double.toString(CARV));

CA涉及到num3,這是一個用戶輸入。所以如果用戶在editText2中輸入100,它應該打印300到tv2。但相反,它給了我一個隨機數字,此刻我假設在打印答案之前需要將上述線以下的額外計算考慮在內。

我的問題是,我如何打印CA * 3的答案?

非常感謝

private OnClickListener myClickListener = new OnClickListener() 
{ 
    public void onClick(View v) { 
     try{ 
     NS=Double.parseDouble(num1.getText().toString()); 
     CH=Double.parseDouble(num2.getText().toString()); 
     CA=Double.parseDouble(num3.getText().toString()); 
     Z=Double.parseDouble(num4.getText().toString()); 
     EKW=Double.parseDouble(num5.getText().toString()); 
     FAT=Double.parseDouble(num6.getText().toString()); 
     CART=Double.parseDouble(num7.getText().toString()); 
     GAT=Double.parseDouble(num8.getText().toString());} 
     catch(Exception e) 
     { 
      if(num1.getText().length()==0) 
      { 
       num1.setError("please input "); 
      } 
      if(num2.getText().length()==0) 
      { 
       num2.setError("please input "); 
      } 
      if(num3.getText().length()==0) 
      { 
       num3.setError("please "); 
      } 
      if(num4.getText().length()==0) 
      { 
       num4.setError("please "); 
      } 
      if(num5.getText().length()==0) 
      { 
       num5.setError("please input "); 
      } 
      if(num6.getText().length()==0) 
      { 
       num6.setError("please input "); 
      } 
      if(num7.getText().length()==0) 
      { 
       num7.setError("please input "); 
      } 
      if(num8.getText().length()==0) 
      { 
       num8.setError("please input "); 
      } 

     } 

     {SV=(((NS*CH)*4)/3600)/Z;SV=(double)(Math.round(SV*100))/100; tv1.setText(Double.toString(SV)); 
     CARV= CA*3; tv2.setText(Double.toString(CARV)); 
     FA= SV*0.1; 
     GA= SV - (CARV + FA); 
     RCARA= CARV/SV; 
     RGA= GA/SV; 
     RFA= FA/SV; 
     CAO=(CARV*RCARA) + (GA*RGA) + (FA*RFA); 
     DT= 26-CAO; 
     RKW= DT * 1.21 * SV;RKW=(double)(Math.round(RKW*100))/100; tv3.setText(Double.toString(RKW)); 
     } 

    } 
}; 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.car1); 

     tv1 = (TextView)findViewById(R.id.textView7); 
     tv2 = (TextView)findViewById(R.id.textView8); 
     tv3 = (TextView)findViewById(R.id.textView8); 


     button01 = (Button)findViewById(R.id.button1); 
     button01.setText("Display result"); 
     button01.setOnClickListener(myClickListener); 

     num1 = (EditText)findViewById(R.id.EditText01); 
     num1.setText(""); 
     num2 = (EditText)findViewById(R.id.editText1); 
     num2.setText(""); 
     num3 = (EditText)findViewById(R.id.editText2); 
     num3.setText(""); 
     num4 = (EditText)findViewById(R.id.editText3); 
     num4.setText(""); 
     num5 = (EditText)findViewById(R.id.editText4); 
     num5.setText(""); 
     num6 = (EditText)findViewById(R.id.editText5); 
     num6.setText("-5"); 
     num7 = (EditText)findViewById(R.id.editText6); 
     num7.setText("10"); 
     num8 = (EditText)findViewById(R.id.editText7); 
     num8.setText("16");   
    } 

}

+2

您確認CA的價值是您期望的嗎? – 2012-07-08 20:08:18

+4

隨意使用空白更慷慨一點。你目前的代碼有點聚集在一些地方 - 特別是在關鍵部分 - 使其難以閱讀。您使用的那個和非標準的命名。 – 2012-07-08 20:08:28

回答

1

我覺得你的問題是在這裏

tv2 = (TextView)findViewById(R.id.textView8); 
tv3 = (TextView)findViewById(R.id.textView8); 

分配相同的TextView到tv2tv3

+0

斑點......愚蠢的錯字......再次感謝。 – Will 2012-07-08 20:28:02