クラス間隔算術平均を計算するプログラムを作成していますが、そのエラーに少しエラーがあります...
例: interval_Values に (10-20,21-30) を入力し、frequency_values に (1,2) を入力すると、計算は次のようになります。
((10+20)/2),((21+30)/2)
そしてそれは与えるでしょう
15,25.5
次に、これらの値をfrequency_Valuesの値に乗算します
(15*1)+(25.5*2)
これにより、次の結果が得られます
(15+51)=66
そしてこれらの後。66 を frequency_Values の合計に割ります。
(1+3)
そう
66/3=22
私のプログラムでこれらの値を入力すると、結果は 15 になります。エラーは何でしょうか。
final AutoCompleteTextView interval_Values = (AutoCompleteTextView) findViewById(R.id.interval_Values);
final AutoCompleteTextView frequency_Values = (AutoCompleteTextView) findViewById(R.id.frequency_Values);
final TextView txtSummation = (TextView) findViewById(R.id.txtSummation);
final TextView txtArithmetic = (TextView) findViewById(R.id.txtArithmetic);
Button btncalculate = (Button) findViewById(R.id.btncalculate);
btncalculate.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v) {
String[] interval = interval_Values.getText().toString().split(",");
String[] frequency= frequency_Values.getText().toString().split(",");
double [] x = new double[interval.length];
double [] y = new double[frequency.length];
double freq=0;
double xy=0;
double result=0;
for(int j=0;j<interval.length;j++){
String[] intr=interval[j].split("-");
x[j]=Double.parseDouble(intr[j]);
double midpoint=((x[0])+(x[1]))/2;
y[j]=Double.parseDouble(frequency[j]);
freq+=y[j];
xy+=midpoint*y[j];
result =xy/freq;
}
txtArithmetic.setText(Double.toString(result));