Reputation: 21
Ok,
So I'm hoping this should be quite a simple problem for someone out there.
The program works just fine, no errors, no crashes so thats a good start!
The problem is I'm getting an incorrect answer.
About half way down you should be able to see the line
CARV= CA*3; tv2.setText(Double.toString(CARV));
CA
relates to num3
, which is a user input. so if the user inputs 100 in editText2
it should print 300 to tv2
. But instead it is giving me a random number, at the moment I'm assume it takes the additional calculations below the above line into account before printing the answer.
My question, is how do i print the answer to CA*3??
Many Thanks
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");
}
}
Upvotes: 0
Views: 119
Reputation: 3058
I think your problem is here
tv2 = (TextView)findViewById(R.id.textView8);
tv3 = (TextView)findViewById(R.id.textView8);
You assign the same TextView to tv2
and tv3
.
Upvotes: 1