-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTest.java.save
More file actions
103 lines (91 loc) · 3.02 KB
/
Test.java.save
File metadata and controls
103 lines (91 loc) · 3.02 KB
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
96
97
98
99
100
101
102
103
import java.util.ArrayList;
import java.util.Collections;
import java.util.Random;
public class Test {
public static double getRan(int n) {
double x = 1000;
double u = 0;
double a = 24693;
double c = 3967;
double K = Math.pow(2, 15);
for (int i = 0; i < n; i++) {
x = (a * x + c) % K;
u = x / K;
}
return u;
}
public static double getX(double u) {
return -12 * Math.log(1 - u);
}
public static double getTime(int r) {
if (r >= 0 && r <= 1) {
return 10;
} else if (r >= 2 && r <= 4) {
return 32;
} else {
return 0;
}
}
public static double getMean(ArrayList<Double> trials) {
double sum = 0;
for (Double trial : trials) {
sum += trial;
}
return sum / trials.size();
}
public static void main(String[] args) {
ArrayList<Double> trials = new ArrayList<>();
Random r = new Random();
int n = 1000;
for (int i = 0; i < n; i++) {
double time = getTime(r.nextInt(10));
if (time == 0) {
double inverse = getX(getRan(i));
time += inverse < 25 ? 6 + inverse : 32;
}
trials.add(time);
}
Collections.sort(trials);
// MEAN
System.out.println("MEAN = " + getMean(trials));
// MEDIANS
int size = trials.size();
// Q1 MEDIAN
double q1median = (trials.get(size / 4) + trials.get(size / 4 - 1)) / 2;
System.out.println("Quartile 1 = " + q1median);
// MEDIAN
double median = (trials.get(size / 2) + trials.get(size / 2 - 1)) / 2;
System.out.println("MEDIAN = " + median);
// Q3 MEDIAN
double q3median = (trials.get(3 * size / 4) + trials.get(3 * size / 4 - 1)) / 2;
System.out.println("Quartile 3 = " + q3median);
int sum = 0;
double w1, w2, w3, w4, w5, w6, w7;
w1 = w2 = w3 = w4 = w5 = w6 = w7 = 0;
for (int i = 0; i < trials.size(); i++) {
sum += trials.get(i);
if (trials.get(i) <= 15)
w1++;
if (trials.get(i) <= 20)
w2++;
if (trials.get(i) <= 30)
w3++;
if (trials.get(i) > 40)
w4++;
if (trials.get(i) > 25)
w5++;
if (trials.get(i) > 28)
w6++;
if (trials.get(i) > 31)
w7++; // System.out.println("P[W <= 15] = " + sum / );
}
System.out.println("P[W <= 15] = " + w1/1000);
System.out.println("P[W <= 20] = " + w2/1000);
System.out.println("P[W <= 30] = " + w3/1000);
System.out.println("P[W > 40] = " + w4/1000);
System.out.println("P[W > 25] = " + w5/1000);
System.out.println("P[W > 28] = " + w6/1000);
System.out.println("P[W > 31] = " + w7/1000);
System.out.println(Collections.max(trials));
}
}