Skip to content

Commit 325d844

Browse files
authored
Create ExampleApp.java
1 parent d1a2633 commit 325d844

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package com.lewdev.probabilitylib;
2+
3+
public class App {
4+
5+
public static void main(String[] args) {
6+
ProbabilityCollection<String> collection = new ProbabilityCollection<>();
7+
8+
collection.add("A", 50);
9+
collection.add("B", 25);
10+
collection.add("C", 10);
11+
12+
int a = 0, b = 0, c = 0;
13+
int totalGets = 100000;
14+
15+
for(int i = 0; i < totalGets; i++) {
16+
String random = collection.get();
17+
18+
if(random.equals("A")) a++;
19+
else if(random.equals("B")) b++;
20+
else if(random.equals("C")) c++;
21+
}
22+
23+
double aProb = 50.0 / (double) collection.getTotalProbability() * 100;
24+
double bProb = 25.0 / (double) collection.getTotalProbability() * 100;
25+
double cProb = 10.0 / (double) collection.getTotalProbability() * 100;
26+
27+
double aResult = a / (double) totalGets * 100;
28+
double bResult = b / (double) totalGets * 100;
29+
double cResult = c / (double) totalGets * 100;
30+
31+
System.out.println(" Prob | Actual");
32+
System.out.println("-----------------------");
33+
System.out.printf("A: %.3f%% | %.3f%% \n", aProb, aResult);
34+
System.out.printf("B: %.3f%% | %.3f%% \n", bProb, bResult);
35+
System.out.printf("C: %.3f%% | %.3f%% \n", cProb, cResult);
36+
}
37+
}

0 commit comments

Comments
 (0)