-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTxtWriter.java
More file actions
192 lines (146 loc) · 7.91 KB
/
TxtWriter.java
File metadata and controls
192 lines (146 loc) · 7.91 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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
package Individual_Project;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
/**
* The class Txt writer
*/
public class TxtWriter {
private BufferedWriter writer;
/**
*
* It is a constructor.
*
* @param fileToWrite the file to write
* @throws IOException
*/
public TxtWriter(String fileToWrite) throws IOException {
this.writer = new BufferedWriter(new FileWriter(fileToWrite));
}
void initializeFile(String name) throws IOException {
writer.write(name);
}
void closeFile() throws IOException {
writer.close();
}
void addBest() throws IOException {
double minCost = Route.routes.first().getCost();
for (Route route: Route.routes) {
if (route.getCost() != minCost) {
return;
}
writer.write("\n\nBest method with haversine\n\n");
for (State state: route.getRoute()) {
double initial_x = state.getX();
String final_string_x = String.valueOf(initial_x);
double initial_y = state.getY();
String final_string_y = String.valueOf(initial_y);
for (int i = 0; i < Y_test.Y_tests.size(); i++) {
if (final_string_x.equals(X_test.X_tests.get(i).toString()) && final_string_y.equals(Y_test.Y_tests.get(i).toString())) {
for (int j = 0; j < SourceAirportID.cities2.size(); j++) {
if (City.cities.get(i).toString().equals(SourceAirportID.cities2.get(j).toString())) {
String a = AirlinesCode.AirlinesCodes.get(j).toString() + ", "+ SourceAirportID.cities2.get(j).toString() + ", " + DestinationAirportID.cities3.get(j).toString() + ", " + Stops.cities4.get(j).toString();
String[] source_destination;
source_destination = a.split(", ");
AirlinesCode1 airlinesCode1 = new AirlinesCode1(source_destination[0]); //storing destination in array.
AirlinesCode1.airlinesCodes1.add(airlinesCode1);
City1 city1 = new City1(source_destination[1]); //storing destination in array.
City1.cities1.add(city1);
Destination destination = new Destination(source_destination[2]); //storing destination in array.
Destination.destination1.add(destination);
Stops1 stops1 = new Stops1(source_destination[3]); //storing destination in array.
Stops1.stops1.add(stops1);
}
}
}
}
}
int l = 0;
int m = 0;
try {
for (int i = 0; i < City1.cities1.size(); i++) {
for (int j = 0; j < City1.cities1.size(); j++) {
if (City1.cities1.get(i).toString().equals(Destination.destination1.get(j).toString())) {
for (int k = 0; j < City1.cities1.size(); k++) {
if (!City1.cities1.get(k).toString().equals(City1.cities1.get(k + 1).toString())) {
l++;
Integer n = Integer.valueOf(Stops1.stops1.get(k).toString());
m = m + n;
writer.write(l+". " + AirlinesCode1.airlinesCodes1.get(k)+ " from " + City1.cities1.get(k) + " to " + City1.cities1.get(k + 1)+ " " + Stops1.stops1.get(k).toString() + " stops\n");
}
}
}
}
}
} catch (Exception e) {
}
writer.write("\n\nTotal flights: "+ l+"\n");
writer.write("Total additional stops: " + m+"\n");
}
writer.write("");
}
void addRoutes() throws IOException {
writer.write("\n\nNo best path, normal route\n\n");
int cnt = 1;
Air_Port firstAir_Port = Route.routes.first().getAir_Port();
for (Route route: Route.routes) {
if (cnt == 1) {
writer.write("");
} else {
if (firstAir_Port.equals(route.getAir_Port())) {
writer.write("");
cnt = cnt - 1;
} else {
writer.write("");
}
}
for (State state: route.getRoute()) {
double initial_x = state.getX();
String final_string_x = String.valueOf(initial_x);
double initial_y = state.getY();
String final_string_y = String.valueOf(initial_y);
for (int i = 0; i < Y_test.Y_tests.size(); i++) {
if (final_string_x.equals(X_test.X_tests.get(i).toString()) && final_string_y.equals(Y_test.Y_tests.get(i).toString())) {
for (int j = 0; j < SourceAirportID.cities2.size(); j++) {
if (City.cities.get(i).toString().equals(SourceAirportID.cities2.get(j).toString())) {
String a = AirlinesCode.AirlinesCodes.get(j).toString() + ", "+ SourceAirportID.cities2.get(j).toString() + ", " + DestinationAirportID.cities3.get(j).toString() + ", " + Stops.cities4.get(j).toString();
String[] source_destination;
source_destination = a.split(", ");
AirlinesCode1 airlinesCode1 = new AirlinesCode1(source_destination[0]); //storing destination in array.
AirlinesCode1.airlinesCodes1.add(airlinesCode1);
City1 city1 = new City1(source_destination[1]); //storing destination in array.
City1.cities1.add(city1);
Destination destination = new Destination(source_destination[2]); //storing destination in array.
Destination.destination1.add(destination);
Stops1 stops1 = new Stops1(source_destination[3]); //storing destination in array.
Stops1.stops1.add(stops1);
}
}
}
}
}
int l = 0;
int m = 0;
try {
for (int i = 0; i < City1.cities1.size(); i++) {
for (int j = 0; j < City1.cities1.size(); j++) {
if (City1.cities1.get(i).toString().equals(Destination.destination1.get(j).toString())) {
for (int k = 0; j < City1.cities1.size(); k++) {
if (!City1.cities1.get(k).toString().equals(City1.cities1.get(k + 1).toString())) {
l++;
Integer n = Integer.valueOf(Stops1.stops1.get(k).toString());
m = m + n;
writer.write(l+". " + AirlinesCode1.airlinesCodes1.get(k)+ " from " + City1.cities1.get(k) + " to " + City1.cities1.get(k + 1)+ " " + Stops1.stops1.get(k).toString() + " stops\n");
}
}
}
}
}
} catch (Exception e) {
}
writer.write("\n\nTotal flights: "+ l+"\n");
writer.write("Total additional stops: " + m);
cnt++;
}
}
}