-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNumeratorCalculate.java
56 lines (48 loc) · 1.06 KB
/
NumeratorCalculate.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/**
*
*/
import java.util.ArrayList;
import java.util.List;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
/**
* @author alan-king
*
* the class is going to calculate the numerator;
*
*
*/
public class NumeratorCalculate {
//add global varieties
protected List<String> xList , yList;
public NumeratorCalculate(List<String> xList ,List<String> yList){
this.xList = xList;
this.yList = yList;
}
/**
* add operate method
*/
public double calcuteNumerator(){
double result =0.0;
double xAverage = 0.0;
double temp = 0.0;
int xSize = xList.size();
for(int x=0;x<xSize;x++){
temp += Double.parseDouble(xList.get(x));
}
xAverage = temp/xSize;
double yAverage = 0.0;
temp = 0.0;
int ySize = yList.size();
for(int x=0;x<ySize;x++){
temp += Double.parseDouble(yList.get(x));
}
yAverage = temp/ySize;
//double sum = 0.0;
for(int x=0;x<xSize;x++){
result+=(Double.parseDouble(xList.get(x))-xAverage)*(Double.parseDouble(yList.get(x))-yAverage);
}
return result;
}
}