-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRaceControl.java
More file actions
116 lines (98 loc) · 4.83 KB
/
Copy pathRaceControl.java
File metadata and controls
116 lines (98 loc) · 4.83 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
104
105
106
107
108
109
110
111
112
113
114
115
116
import java.util.*;
import java.io.*;
public class RaceControl {
public static void main(String[] args) {
ArrayList<Driver> grid2024 = new ArrayList<>();
ArrayList<Driver> grid2025 = new ArrayList<>();
String racers2024 = "f1drivers2024.csv";
String racers2025 = "f1drivers2025.csv";
try {
//Adds 2024 data to the grid arrayList as Driver objects
Scanner fileReader2024 = new Scanner(new File(racers2024));
//Remove first entry
fileReader2024.nextLine();
//Loop through the file
while (fileReader2024.hasNextLine()) {
String line = fileReader2024.nextLine();
//Split the line by comma
String[] data = line.split(",");
//Parse data and create Athlete object
grid2024.add(new Driver(
data[0], data[1], Double.parseDouble(data[2]), Double.parseDouble(data[3]),
Double.parseDouble(data[4])
));
}
fileReader2024.close();
System.out.println("Successfully loaded " + grid2024.size() + " records.");
//Adds 2025 data to the grid arrayList as Driver objects
Scanner fileReader2025 = new Scanner(new File(racers2025));
//Remove first entry
fileReader2025.nextLine();
//Loop through the file
while (fileReader2025.hasNextLine()) {
String line = fileReader2025.nextLine();
//Split the line by comma
String[] data = line.split(",");
//Parse data and create Athlete object
grid2025.add(new Driver(
data[0], data[1], Double.parseDouble(data[2]), Double.parseDouble(data[3]),
Double.parseDouble(data[4])));
}
fileReader2025.close();
System.out.println("Successfully loaded " + grid2025.size() + " records.");
}
catch (FileNotFoundException e) {
System.out.println("Error: The file '" + racers2025 + "' was not found.");
} catch (NumberFormatException e) {
System.out.println("Error: Failed to parse a numeric value in the CSV.");
}
// System.out.println("2024 Racers: \n");
// for (Driver d:grid2024){
// System.out.println(d.toString());
// }
// System.out.println("\n2025 Racers: ");
// for (Driver d:grid2025){
// System.out.println(d.toString());
//}
System.out.println("Between 2024 and 2025, ");
for(int i = 0; i<grid2025.size();i++){
String currentDriver = grid2025.get(i).getName();
for (int j = 0; j<grid2024.size();j++){
String name = grid2024.get(j).getName();
double podiumPercent;
double winPercent;
double champPercent;
if (grid2024.get(j).getPodiums() != 0){
podiumPercent = (((grid2025.get(i).getPodiums())/(grid2024.get(j).getPodiums()))*100)-100;
}
else{
podiumPercent = 0;
}
if (grid2024.get(j).getWins() != 0){
winPercent = (((grid2025.get(i).getWins())/(grid2024.get(j).getWins()))*100)-100;
}
else{
winPercent = 0;
}
if (grid2024.get(j).getChampPoints() != 0){
champPercent = (((grid2025.get(i).getChampPoints())/(grid2024.get(j).getChampPoints()))*100)-100;
}
else{
champPercent = 0;
}
if (currentDriver.equals(name)){
if ((grid2025.get(i).getTeam()).equals((grid2024.get(j).getTeam()))){
System.out.printf("\nDriver " + currentDriver + " raced on " + (grid2025.get(i).getTeam()) +
" in both years, had a %.2f%% change in podiums, a %.2f%% change in wins, and a %.2f%% change in championship points",
podiumPercent, winPercent, champPercent);
} else {
System.out.printf("\nDriver " + currentDriver + " moved from " + grid2024.get(j).getTeam() +
" to " + grid2025.get(i).getTeam() +
", had a %.2f%% change in podiums, a %.2f%% change in wins, and a %.2f%% change in championship points",
podiumPercent, winPercent, champPercent);
}
}
}
}
}
}