diff options
| author | Martial Simon <msimon_fr@hotmail.com> | 2025-09-15 01:08:27 +0200 |
|---|---|---|
| committer | Martial Simon <msimon_fr@hotmail.com> | 2025-09-15 01:08:27 +0200 |
| commit | c9b6b9a5ca082fe7c1b6f58d7713f785a9eb6a5c (patch) | |
| tree | 3e4f42f93c7ae89a364e4d51fff6e5cec4e55fa9 /graphs/java/travel/src/main | |
add: graphs et rushs
Diffstat (limited to 'graphs/java/travel/src/main')
3 files changed, 86 insertions, 0 deletions
diff --git a/graphs/java/travel/src/main/java/fr/epita/assistants/travel/Country.java b/graphs/java/travel/src/main/java/fr/epita/assistants/travel/Country.java new file mode 100644 index 0000000..e616e64 --- /dev/null +++ b/graphs/java/travel/src/main/java/fr/epita/assistants/travel/Country.java @@ -0,0 +1,44 @@ +package fr.epita.assistants.travel; + +import com.opencsv.CSVReader; + +import java.io.FileReader; +import java.time.ZoneId; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Objects; + +public class Country { + String countryName; + public Map<String, Integer> travelTimes; + ZoneId countryZone; + String filename; + + public Country(String countryName, String countryZone, String inputFilePath) { + this.countryName = countryName; + this.countryZone = ZoneId.of(countryZone); + this.filename = inputFilePath; + this.travelTimes = initTravelTimes(inputFilePath); + } + + public Map<String, Integer> initTravelTimes(String inputFilePath) { + Map<String, Integer> res = new HashMap<>(); + try { + CSVReader c = new CSVReader(new FileReader(inputFilePath)); + List<String[]> lines = c.readAll(); + lines.removeFirst(); + for (String[] line : lines) { + if (Objects.equals(line[0], this.countryName)) { + res.put(line[1], Integer.parseInt(line[2])); + } + else if (Objects.equals(line[1], this.countryName)) { + res.put(line[0], Integer.parseInt(line[2])); + } + } + } catch (Exception e) { + throw new RuntimeException(e); + } + return res; + } +} diff --git a/graphs/java/travel/src/main/java/fr/epita/assistants/travel/Travel.java b/graphs/java/travel/src/main/java/fr/epita/assistants/travel/Travel.java new file mode 100644 index 0000000..9302e18 --- /dev/null +++ b/graphs/java/travel/src/main/java/fr/epita/assistants/travel/Travel.java @@ -0,0 +1,13 @@ +package fr.epita.assistants.travel; + +import java.time.ZonedDateTime; +import java.time.format.DateTimeFormatter; + +public class Travel { + public static void travelTo(Country source, Country destination) { + ZonedDateTime t1 = ZonedDateTime.now(source.countryZone); + ZonedDateTime t2 = ZonedDateTime.now(destination.countryZone).plusHours(source.travelTimes.get(destination.countryName)); + System.out.println("Boarding in " + source.countryName + ", local date and time is: " + t1.format(DateTimeFormatter.RFC_1123_DATE_TIME)); + System.out.println("Landing in " + destination.countryName + ", local date and time on arrival will be: " + t2.format(DateTimeFormatter.RFC_1123_DATE_TIME)); + } +} diff --git a/graphs/java/travel/src/main/resources/travel_times.csv b/graphs/java/travel/src/main/resources/travel_times.csv new file mode 100644 index 0000000..a6b720b --- /dev/null +++ b/graphs/java/travel/src/main/resources/travel_times.csv @@ -0,0 +1,29 @@ +source,destination,travel_time +France,Italy,1 +France,England,2 +France,Vietnam,12 +France,Chicago,9 +France,Brazil,12 +France,Egypt,4 +France,Australia,24 +Italy,England,3 +Italy,Vietnam,11 +Italy,Chicago,9 +Italy,Brazil,12 +Italy,Egypt,3 +Italy,Australia,17 +England,Vietnam,12 +England,Chicago,11 +England,Brazil,12 +England,Egypt,5 +England,Australia,21 +Vietnam,Chicago,21 +Vietnam,Brazil,21 +Vietnam,Egypt,17 +Vietnam,Australia,6 +Chicago,Brazil,13 +Chicago,Egypt,13 +Chicago,Australia,21 +Brazil,Egypt,17 +Brazil,Australia,21 +Egypt,Australia,19
\ No newline at end of file |
