-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSingle.java
95 lines (81 loc) · 1.92 KB
/
Single.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import java.util.Arrays;
public class Single {
public class DataTunggal{
public double[] data;
public boolean sampel;
public DataTunggal(double[] data, boolean sampel){
this.sampel = sampel;
this.data = data;
}
public void sort(){
Double[] data2 = new Double[data.length];
int n = data.length;
for (int i = 0; i < n; ++i){
data2[i] = data[i];
}
Arrays.sort(data2);
this.data = new double[data.length];
for(int i = 0; i < n; ++i){
this.data[i] = data2[i];
}
}
public double mean(){
int n = data.length;
double sum = 0;
for(int i = 0; i < n; ++i){
sum += data[i];
}
return sum/n;
}
public double median(){
int n = data.length;
if(n%2==0){
return (data[n/2] + data[(n/2)+1])/2;
}else{
return data[(n+1)/2];
}
}
public double modus(){
return 0; //todo
}
public double max(){
return data[data.length-1];
}
public double min(){
return data[0];
}
public double range(){
return max()-min();
}
public double deltaXMean(int i, double mean){
return Math.abs(data[i]-mean);
}
public double sqDeltaXMean(int i, double mean){
double deltaXMean = deltaXMean(i, mean);
return deltaXMean*deltaXMean;
}
public double sr(){
double mean = mean();
int n = data.length;
double sum = 0;
for(int i = 0; i < n; ++i){
sum += deltaXMean(i, mean);
}
return sum/n;
}
public double v(){
double mean = mean();
int n = data.length;
double sum = 0;
for(int i = 0; i < n; ++i){
sum+= sqDeltaXMean(i, mean);
}
return sum/n;
}
public double s(){
return Math.sqrt(v());
}
}
public static void main(String[] args) {
}
}