-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChampionshipManager.java
More file actions
64 lines (53 loc) · 1.61 KB
/
ChampionshipManager.java
File metadata and controls
64 lines (53 loc) · 1.61 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
package main;
import java.util.ArrayList;
import java.util.List;
public class ChampionshipManager {
private static ChampionshipManager instance;
private List<Driver> drivers;
private List<RallyRaceResult> races;
private static int totalDrivers = 0;
private static int totalRaces = 0;
private ChampionshipManager() {
drivers = new ArrayList<>();
races = new ArrayList<>();
}
public static ChampionshipManager getInstance() {
if (instance == null) {
instance = new ChampionshipManager();
}
return instance;
}
public void registerDriver(Driver driver) {
drivers.add(driver);
totalDrivers++;
}
public void addRaceResult(RallyRaceResult result) {
races.add(result);
totalRaces++;
}
public List<Driver> getDriverStandings() {
drivers.sort((d1, d2) -> d2.getPoints() - d1.getPoints());
return drivers;
}
public static Driver getLeadingDriver() {
if (instance == null || instance.drivers.isEmpty()) {
return null;
}
return instance.getDriverStandings().get(0);
}
public static int getTotalChampionshipPoints() {
if (instance == null) {
return 0;
}
return instance.drivers.stream().mapToInt(Driver::getPoints).sum();
}
public static int getTotalDrivers() {
return totalDrivers;
}
public static int getTotalRaces() {
return totalRaces;
}
public List<RallyRaceResult> getRaces() {
return races;
}
}