-
Notifications
You must be signed in to change notification settings - Fork 0
/
FraudDetectionModule.java
60 lines (50 loc) · 2.03 KB
/
FraudDetectionModule.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
import java.util.*;
public class FraudDetectionModule {
private List<Map<String, String>> suspiciousActivities;
private Set<String> blacklistedUsers;
public FraudDetectionModule() {
suspiciousActivities = new ArrayList<>();
blacklistedUsers = new HashSet<>();
}
public void monitorRides(RideSharingSystem rideSharingSystem) {
for (Ride ride : rideSharingSystem.getActiveRides().values()) {
if (detectFraud(ride)) {
flagActivity(ride.getPassengerId(), "Unusually high fare");
flagActivity(ride.getDriverId(), "Unusually high fare in repeated rides");
}
}
}
private boolean detectFraud(Ride ride) {
return ride.getFare() > 100.0f; // Example threshold
}
public void flagActivity(String userId, String reason) {
Map<String, String> activity = new HashMap<>();
activity.put("user_id", userId);
activity.put("reason", reason);
suspiciousActivities.add(activity);
System.out.println("User " + userId + " flagged for: " + reason);
}
public void blockUser(String userId) {
blacklistedUsers.add(userId);
System.out.println("User " + userId + " has been blacklisted.");
}
public void analyzePatterns() {
Map<String, Integer> userFraudCounts = new HashMap<>();
for (Map<String, String> activity : suspiciousActivities) {
String userId = activity.get("user_id");
userFraudCounts.put(userId, userFraudCounts.getOrDefault(userId, 0) + 1);
}
for (Map.Entry<String, Integer> entry : userFraudCounts.entrySet()) {
if (entry.getValue() >= 3) { // Example threshold for blacklisting
blockUser(entry.getKey());
}
}
}
// Getters for suspicious activities and blacklisted users
public List<Map<String, String>> getSuspiciousActivities() {
return suspiciousActivities;
}
public Set<String> getBlacklistedUsers() {
return blacklistedUsers;
}
}