Algorithms
Data Structures
Simulation
Logic
Games
Date Time
import java.time.LocalTime; import java.time.format.DateTimeFormatter; import java.util.HashMap; import java.util.Map; public class Kata { public static String arrivalTime(final String[] route, final String departureTime) { if (route.length == 0) return "The Train Driver has the day off"; LocalTime timeResult = LocalTime.parse(departureTime, DateTimeFormatter.ofPattern("HH:mm")); String origin = "Skyport"; int index = 0; while (index < route.length) { String destination = route[index]; Map<String, double[]> destinationMap = tableTime.get(origin); if (destinationMap != null && destinationMap.containsKey(destination)) { double[] times = destinationMap.get(destination); timeResult = calculateTime(timeResult, times); origin = destination; index++; } else if (origin.equals(destination)) { timeResult = timeResult.plusHours(1); index++; } else { String transfer = "Skyport"; double[] times = tableTime.get(origin).get(transfer); timeResult = calculateTime(timeResult, times); origin = transfer; } } return timeResult.format(DateTimeFormatter.ofPattern("HH:mm")); } private static Map<String, Map<String, double[]>> tableTime = new HashMap<String, Map<String, double[]>>() { { addRecord("Skyport", "Crystalium", 15, 2); addRecord("Skyport", "Oasis", 20, 3); addRecord("Oasis", "Crystalium", 15, 1.5); addRecord("Skyport", "Nexus", 15, 4); } private void addRecord(final String origin, final String destiny, final double minutesWait, final double hoursTravel) { putIfAbsent(origin, new HashMap<>()); get(origin).put(destiny, new double[] { minutesWait, hoursTravel }); putIfAbsent(destiny, new HashMap<>()); get(destiny).put(origin, new double[] { minutesWait - 5, hoursTravel }); } }; private static LocalTime calculateTime(final LocalTime currentTime, final double[] times) { int minutes = (int) times[0]; int remainingMinutes = (int) (times[1] * 60); return currentTime.plusMinutes(minutes).plusMinutes(remainingMinutes); } }
- import java.time.LocalTime;
- import java.time.format.DateTimeFormatter;
- import java.util.HashMap;
- import java.util.Map;
- public class Kata {
- public static String arrivalTime(final String[] route, final String departureTime) {
if (route.length == 0)return "The Train Driver has the day off";- if (route.length == 0) return "The Train Driver has the day off";
- LocalTime timeResult = LocalTime.parse(departureTime, DateTimeFormatter.ofPattern("HH:mm"));
- String origin = "Skyport";
- int index = 0;
while(index < route.length) {- while (index < route.length) {
- String destination = route[index];
- Map<String, double[]> destinationMap = tableTime.get(origin);
- if (destinationMap != null && destinationMap.containsKey(destination)) {
- double[] times = destinationMap.get(destination);
- timeResult = calculateTime(timeResult, times);
- origin = destination;
index++;- index++;
- } else if (origin.equals(destination)) {
- timeResult = timeResult.plusHours(1);
index++;- index++;
- } else {
- String transfer = "Skyport";
- double[] times = tableTime.get(origin).get(transfer);
- timeResult = calculateTime(timeResult, times);
- origin = transfer;
- }
- }
- return timeResult.format(DateTimeFormatter.ofPattern("HH:mm"));
- }
- private static Map<String, Map<String, double[]>> tableTime = new HashMap<String, Map<String, double[]>>() {
- {
- addRecord("Skyport", "Crystalium", 15, 2);
- addRecord("Skyport", "Oasis", 20, 3);
- addRecord("Oasis", "Crystalium", 15, 1.5);
- addRecord("Skyport", "Nexus", 15, 4);
- }
private void addRecord(final String origin, final String destiny, final double minutesWait, final double hoursTravel) {- private void addRecord(final String origin, final String destiny, final double minutesWait,
- final double hoursTravel) {
- putIfAbsent(origin, new HashMap<>());
- get(origin).put(destiny, new double[] { minutesWait, hoursTravel });
- putIfAbsent(destiny, new HashMap<>());
- get(destiny).put(origin, new double[] { minutesWait - 5, hoursTravel });
- }
- };
- private static LocalTime calculateTime(final LocalTime currentTime, final double[] times) {
- int minutes = (int) times[0];
- int remainingMinutes = (int) (times[1] * 60);
- return currentTime.plusMinutes(minutes).plusMinutes(remainingMinutes);
- }
- }
import org.junit.jupiter.api.RepeatedTest; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; import java.time.LocalTime; import java.time.format.DateTimeFormatter; import java.util.Arrays; import java.util.HashMap; import java.util.Map; import java.util.Random; class SolutionTest { /*-----------------------------SAMPLE TEST CASES----------------------------*/ @Test void testSingleDestination() { String[] route = { "Crystalium" }; String departureTime = "10:00"; String expected = "12:15"; String result = Kata.arrivalTime(route, departureTime); String msg = "Input: " + Arrays.toString(route) + ", " + departureTime; assertEquals(expected, result, msg); } @Test void testMultipleDestinations() { String[] route = { "Crystalium", "Skyport", "Oasis" }; String departureTime = "10:00"; String expected = "17:45"; String result = Kata.arrivalTime(route, departureTime); String msg = "Input: " + Arrays.toString(route) + ", " + departureTime; assertEquals(expected, result, msg); } @Test void testDepartingFromMidnight() { String[] route = { "Nexus", "Skyport", "Oasis" }; String departureTime = "21:30"; String expected = "09:15"; String result = Kata.arrivalTime(route, departureTime); String msg = "Input: " + Arrays.toString(route) + ", " + departureTime; assertEquals(expected, result, msg); } @Test void testNoDestinations() { String[] route = {}; String departureTime = "12:00"; String expected = "The Train Driver has the day off"; String result = Kata.arrivalTime(route, departureTime); String msg = "Input: " + Arrays.toString(route) + ", " + departureTime; assertEquals(expected, result, msg); } /*-------------------------------TEST CASES---------------------------------*/ @Test void testStaySkyport() { String[] route = { "Skyport" }; String departureTime = "21:30"; String expected = "22:30"; String result = Kata.arrivalTime(route, departureTime); String msg = "Input: " + Arrays.toString(route) + ", " + departureTime; assertEquals(expected, result, msg); } @Test void testOasisNexus() { String[] route = { "Oasis", "Nexus" }; String departureTime = "06:30"; String expected = "17:20"; String result = Kata.arrivalTime(route, departureTime); String msg = "Input: " + Arrays.toString(route) + ", " + departureTime; assertEquals(expected, result, msg); } @Test void testCrystaliumNexus() { String[] route = { "Crystalium", "Nexus" }; String departureTime = "23:50"; String expected = "08:30"; String result = Kata.arrivalTime(route, departureTime); String msg = "Input: " + Arrays.toString(route) + ", " + departureTime; assertEquals(expected, result, msg); } @Test void testDuplicateCities() { String[] route = { "Crystalium", "Crystalium", "Oasis", "Oasis" }; String departureTime = "00:30"; String expected = "06:25"; String result = Kata.arrivalTime(route, departureTime); String msg = "Input: " + Arrays.toString(route) + ", " + departureTime; assertEquals(expected, result, msg); } @Test void testDuplicateNexus() { String[] route = { "Nexus", "Nexus" }; String departureTime = "20:15"; String expected = "01:30"; String result = Kata.arrivalTime(route, departureTime); String msg = "Input: " + Arrays.toString(route) + ", " + departureTime; assertEquals(expected, result, msg); } @RepeatedTest(50) void testRandom() { Random random = new Random(); String[] possiblesRoutes = { "Skyport", "Crystalium", "Oasis", "Nexus" }; int size = random.nextInt(30, 51); String[] randomRoute = new String[size]; for (int i = 0; i < size; i++) { randomRoute[i] = possiblesRoutes[random.nextInt(possiblesRoutes.length)]; } int hour = random.nextInt(0, 24); int minute = random.nextInt(0, 60); String randomDepartureTime = String.format("%02d:%02d", hour, minute); String result = Kata.arrivalTime(randomRoute, randomDepartureTime); String msg = "Random input: " + Arrays.toString(randomRoute) + ", " + randomDepartureTime; assertEquals(arrivalTime(randomRoute, randomDepartureTime), result, msg); } private static String arrivalTime(final String[] route, final String departureTime) { if (route.length == 0) return "The Train Driver has the day off"; LocalTime timeResult = LocalTime.parse(departureTime, DateTimeFormatter.ofPattern("HH:mm")); String origin = "Skyport"; int index = 0; while (index < route.length) { String destination = route[index]; Map<String, double[]> destinationMap = tableTime.get(origin); if (destinationMap != null && destinationMap.containsKey(destination)) { double[] times = destinationMap.get(destination); timeResult = calculateTime(timeResult, times); origin = destination; index++; } else if (origin.equals(destination)) { timeResult = timeResult.plusHours(1); index++; } else { String transfer = "Skyport"; double[] times = tableTime.get(origin).get(transfer); timeResult = calculateTime(timeResult, times); origin = transfer; } } return timeResult.format(DateTimeFormatter.ofPattern("HH:mm")); } private static Map<String, Map<String, double[]>> tableTime = new HashMap<String, Map<String, double[]>>() { { addRecord("Skyport", "Crystalium", 15, 2); addRecord("Skyport", "Oasis", 20, 3); addRecord("Oasis", "Crystalium", 15, 1.5); addRecord("Skyport", "Nexus", 15, 4); } private void addRecord(final String origin, final String destiny, final double minutesWait, final double hoursTravel) { putIfAbsent(origin, new HashMap<>()); get(origin).put(destiny, new double[] { minutesWait, hoursTravel }); putIfAbsent(destiny, new HashMap<>()); get(destiny).put(origin, new double[] { minutesWait - 5, hoursTravel }); } }; private static LocalTime calculateTime(final LocalTime currentTime, final double[] times) { int minutes = (int) times[0]; int remainingMinutes = (int) (times[1] * 60); return currentTime.plusMinutes(minutes).plusMinutes(remainingMinutes); } }
- import org.junit.jupiter.api.RepeatedTest;
- import org.junit.jupiter.api.Test;
- import static org.junit.jupiter.api.Assertions.assertEquals;
- import java.time.LocalTime;
- import java.time.format.DateTimeFormatter;
- import java.util.Arrays;
- import java.util.HashMap;
- import java.util.Map;
- import java.util.Random;
- class SolutionTest {
- /*-----------------------------SAMPLE TEST CASES----------------------------*/
- @Test
- void testSingleDestination() {
- String[] route = { "Crystalium" };
- String departureTime = "10:00";
- String expected = "12:15";
- String result = Kata.arrivalTime(route, departureTime);
- String msg = "Input: " + Arrays.toString(route) + ", " + departureTime;
- assertEquals(expected, result, msg);
- }
- @Test
- void testMultipleDestinations() {
- String[] route = { "Crystalium", "Skyport", "Oasis" };
- String departureTime = "10:00";
- String expected = "17:45";
- String result = Kata.arrivalTime(route, departureTime);
- String msg = "Input: " + Arrays.toString(route) + ", " + departureTime;
- assertEquals(expected, result, msg);
- }
- @Test
- void testDepartingFromMidnight() {
- String[] route = { "Nexus", "Skyport", "Oasis" };
- String departureTime = "21:30";
- String expected = "09:15";
- String result = Kata.arrivalTime(route, departureTime);
- String msg = "Input: " + Arrays.toString(route) + ", " + departureTime;
- assertEquals(expected, result, msg);
- }
- @Test
- void testNoDestinations() {
- String[] route = {};
- String departureTime = "12:00";
- String expected = "The Train Driver has the day off";
- String result = Kata.arrivalTime(route, departureTime);
- String msg = "Input: " + Arrays.toString(route) + ", " + departureTime;
- assertEquals(expected, result, msg);
- }
- /*-------------------------------TEST CASES---------------------------------*/
- @Test
- void testStaySkyport() {
- String[] route = { "Skyport" };
- String departureTime = "21:30";
- String expected = "22:30";
- String result = Kata.arrivalTime(route, departureTime);
- String msg = "Input: " + Arrays.toString(route) + ", " + departureTime;
- assertEquals(expected, result, msg);
- }
- @Test
- void testOasisNexus() {
- String[] route = { "Oasis", "Nexus" };
- String departureTime = "06:30";
- String expected = "17:20";
- String result = Kata.arrivalTime(route, departureTime);
- String msg = "Input: " + Arrays.toString(route) + ", " + departureTime;
- assertEquals(expected, result, msg);
- }
- @Test
- void testCrystaliumNexus() {
- String[] route = { "Crystalium", "Nexus" };
- String departureTime = "23:50";
- String expected = "08:30";
- String result = Kata.arrivalTime(route, departureTime);
- String msg = "Input: " + Arrays.toString(route) + ", " + departureTime;
- assertEquals(expected, result, msg);
- }
- @Test
- void testDuplicateCities() {
- String[] route = { "Crystalium", "Crystalium", "Oasis", "Oasis" };
- String departureTime = "00:30";
- String expected = "06:25";
- String result = Kata.arrivalTime(route, departureTime);
- String msg = "Input: " + Arrays.toString(route) + ", " + departureTime;
- assertEquals(expected, result, msg);
- }
- @Test
- void testDuplicateNexus() {
- String[] route = { "Nexus", "Nexus" };
- String departureTime = "20:15";
- String expected = "01:30";
- String result = Kata.arrivalTime(route, departureTime);
- String msg = "Input: " + Arrays.toString(route) + ", " + departureTime;
- assertEquals(expected, result, msg);
- }
- @RepeatedTest(50)
- void testRandom() {
- Random random = new Random();
- String[] possiblesRoutes = { "Skyport", "Crystalium", "Oasis", "Nexus" };
- int size = random.nextInt(30, 51);
- String[] randomRoute = new String[size];
- for (int i = 0; i < size; i++) {
- randomRoute[i] = possiblesRoutes[random.nextInt(possiblesRoutes.length)];
- }
- int hour = random.nextInt(0, 24);
- int minute = random.nextInt(0, 60);
- String randomDepartureTime = String.format("%02d:%02d", hour, minute);
- String result = Kata.arrivalTime(randomRoute, randomDepartureTime);
- String msg = "Random input: " + Arrays.toString(randomRoute) + ", " + randomDepartureTime;
- assertEquals(arrivalTime(randomRoute, randomDepartureTime), result, msg);
- }
- private static String arrivalTime(final String[] route, final String departureTime) {
if (route.length == 0)return "The Train Driver has the day off";- if (route.length == 0) return "The Train Driver has the day off";
- LocalTime timeResult = LocalTime.parse(departureTime, DateTimeFormatter.ofPattern("HH:mm"));
- String origin = "Skyport";
for (int i = 0; i < route.length; i++) {String destination = route[i];Map<String, double[]> destinationMap = tabla.get(origin);- int index = 0;
- while (index < route.length) {
- String destination = route[index];
- Map<String, double[]> destinationMap = tableTime.get(origin);
- if (destinationMap != null && destinationMap.containsKey(destination)) {
- double[] times = destinationMap.get(destination);
- timeResult = calculateTime(timeResult, times);
- origin = destination;
- index++;
- } else if (origin.equals(destination)) {
- timeResult = timeResult.plusHours(1);
- index++;
- } else {
String transbordo = "Skyport";double[] times = tabla.get(origin).get(transbordo);- String transfer = "Skyport";
- double[] times = tableTime.get(origin).get(transfer);
- timeResult = calculateTime(timeResult, times);
origin = transbordo;i--;- origin = transfer;
- }
- }
- return timeResult.format(DateTimeFormatter.ofPattern("HH:mm"));
- }
private static Map<String, Map<String, double[]>> tabla = new HashMap<String, Map<String, double[]>>() {- private static Map<String, Map<String, double[]>> tableTime = new HashMap<String, Map<String, double[]>>() {
- {
- addRecord("Skyport", "Crystalium", 15, 2);
- addRecord("Skyport", "Oasis", 20, 3);
- addRecord("Oasis", "Crystalium", 15, 1.5);
- addRecord("Skyport", "Nexus", 15, 4);
- }
- private void addRecord(final String origin, final String destiny, final double minutesWait,
- final double hoursTravel) {
- putIfAbsent(origin, new HashMap<>());
- get(origin).put(destiny, new double[] { minutesWait, hoursTravel });
- putIfAbsent(destiny, new HashMap<>());
- get(destiny).put(origin, new double[] { minutesWait - 5, hoursTravel });
- }
- };
- private static LocalTime calculateTime(final LocalTime currentTime, final double[] times) {
- int minutes = (int) times[0];
- int remainingMinutes = (int) (times[1] * 60);
- return currentTime.plusMinutes(minutes).plusMinutes(remainingMinutes);
- }
- }
import org.junit.jupiter.api.RepeatedTest; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; import java.time.LocalTime; import java.time.format.DateTimeFormatter; import java.util.Arrays; import java.util.HashMap; import java.util.Map; import java.util.Random; class SolutionTest { /*-----------------------------SAMPLE TEST CASES----------------------------*/ @Test void testSingleDestination() { String[] route = { "Crystalium" }; String departureTime = "10:00"; String expected = "12:15"; String result = Kata.arrivalTime(route, departureTime); String msg = "Input: " + Arrays.toString(route) + ", " + departureTime; assertEquals(expected, result, msg); } @Test void testMultipleDestinations() { String[] route = { "Crystalium", "Skyport", "Oasis" }; String departureTime = "10:00"; String expected = "17:45"; String result = Kata.arrivalTime(route, departureTime); String msg = "Input: " + Arrays.toString(route) + ", " + departureTime; assertEquals(expected, result, msg); } @Test void testDepartingFromMidnight() { String[] route = { "Nexus", "Skyport", "Oasis" }; String departureTime = "21:30"; String expected = "09:15"; String result = Kata.arrivalTime(route, departureTime); String msg = "Input: " + Arrays.toString(route) + ", " + departureTime; assertEquals(expected, result, msg); } @Test void testNoDestinations() { String[] route = {}; String departureTime = "12:00"; String expected = "The Train Driver has the day off"; String result = Kata.arrivalTime(route, departureTime); String msg = "Input: " + Arrays.toString(route) + ", " + departureTime; assertEquals(expected, result, msg); } /*-------------------------------TEST CASES---------------------------------*/ @Test void testStaySkyport() { String[] route = { "Skyport" }; String departureTime = "21:30"; String expected = "22:30"; String result = Kata.arrivalTime(route, departureTime); String msg = "Input: " + Arrays.toString(route) + ", " + departureTime; assertEquals(expected, result, msg); } @Test void testOasisNexus() { String[] route = { "Oasis", "Nexus" }; String departureTime = "06:30"; String expected = "17:20"; String result = Kata.arrivalTime(route, departureTime); String msg = "Input: " + Arrays.toString(route) + ", " + departureTime; assertEquals(expected, result, msg); } @Test void testCrystaliumNexus() { String[] route = { "Crystalium", "Nexus" }; String departureTime = "23:50"; String expected = "08:30"; String result = Kata.arrivalTime(route, departureTime); String msg = "Input: " + Arrays.toString(route) + ", " + departureTime; assertEquals(expected, result, msg); } @Test void testDuplicateCities() { String[] route = { "Crystalium", "Crystalium", "Oasis", "Oasis" }; String departureTime = "00:30"; String expected = "06:25"; String result = Kata.arrivalTime(route, departureTime); String msg = "Input: " + Arrays.toString(route) + ", " + departureTime; assertEquals(expected, result, msg); } @Test void testDuplicateNexus() { String[] route = { "Nexus", "Nexus" }; String departureTime = "20:15"; String expected = "01:30"; String result = Kata.arrivalTime(route, departureTime); String msg = "Input: " + Arrays.toString(route) + ", " + departureTime; assertEquals(expected, result, msg); } @RepeatedTest(50) void testRandom() { Random random = new Random(); String[] possiblesRoutes = { "Skyport", "Crystalium", "Oasis", "Nexus" }; int size = random.nextInt(30, 51); String[] randomRoute = new String[size]; for (int i = 0; i < size; i++) { randomRoute[i] = possiblesRoutes[random.nextInt(possiblesRoutes.length)]; } int hour = random.nextInt(0, 24); int minute = random.nextInt(0, 60); String randomDepartureTime = String.format("%02d:%02d", hour, minute); String result = Kata.arrivalTime(randomRoute, randomDepartureTime); String msg = "Random input: " + Arrays.toString(randomRoute) + ", " + randomDepartureTime; assertEquals(arrivalTime(randomRoute, randomDepartureTime), result, msg); } private static String arrivalTime(final String[] route, final String departureTime) { if (route.length == 0) return "The Train Driver has the day off"; LocalTime timeResult = LocalTime.parse(departureTime, DateTimeFormatter.ofPattern("HH:mm")); String origin = "Skyport"; for (int i = 0; i < route.length; i++) { String destination = route[i]; Map<String, double[]> destinationMap = tabla.get(origin); if (destinationMap != null && destinationMap.containsKey(destination)) { double[] times = destinationMap.get(destination); timeResult = calculateTime(timeResult, times); origin = destination; } else if (origin.equals(destination)) { timeResult = timeResult.plusHours(1); } else { String transbordo = "Skyport"; double[] times = tabla.get(origin).get(transbordo); timeResult = calculateTime(timeResult, times); origin = transbordo; i--; } } return timeResult.format(DateTimeFormatter.ofPattern("HH:mm")); } private static Map<String, Map<String, double[]>> tabla = new HashMap<String, Map<String, double[]>>() { { addRecord("Skyport", "Crystalium", 15, 2); addRecord("Skyport", "Oasis", 20, 3); addRecord("Oasis", "Crystalium", 15, 1.5); addRecord("Skyport", "Nexus", 15, 4); } private void addRecord(final String origin, final String destiny, final double minutesWait, final double hoursTravel) { putIfAbsent(origin, new HashMap<>()); get(origin).put(destiny, new double[] { minutesWait, hoursTravel }); putIfAbsent(destiny, new HashMap<>()); get(destiny).put(origin, new double[] { minutesWait - 5, hoursTravel }); } }; private static LocalTime calculateTime(final LocalTime currentTime, final double[] times) { int minutes = (int) times[0]; int remainingMinutes = (int) (times[1] * 60); return currentTime.plusMinutes(minutes).plusMinutes(remainingMinutes); } }
- import org.junit.jupiter.api.RepeatedTest;
- import org.junit.jupiter.api.Test;
- import static org.junit.jupiter.api.Assertions.assertEquals;
- import java.time.LocalTime;
- import java.time.format.DateTimeFormatter;
- import java.util.Arrays;
- import java.util.HashMap;
- import java.util.Map;
- import java.util.Random;
- class SolutionTest {
- /*-----------------------------SAMPLE TEST CASES----------------------------*/
- @Test
- void testSingleDestination() {
- String[] route = { "Crystalium" };
- String departureTime = "10:00";
- String expected = "12:15";
- String result = Kata.arrivalTime(route, departureTime);
- String msg = "Input: " + Arrays.toString(route) + ", " + departureTime;
- assertEquals(expected, result, msg);
- }
- @Test
- void testMultipleDestinations() {
- String[] route = { "Crystalium", "Skyport", "Oasis" };
- String departureTime = "10:00";
- String expected = "17:45";
- String result = Kata.arrivalTime(route, departureTime);
- String msg = "Input: " + Arrays.toString(route) + ", " + departureTime;
- assertEquals(expected, result, msg);
- }
- @Test
- void testDepartingFromMidnight() {
- String[] route = { "Nexus", "Skyport", "Oasis" };
- String departureTime = "21:30";
- String expected = "09:15";
- String result = Kata.arrivalTime(route, departureTime);
- String msg = "Input: " + Arrays.toString(route) + ", " + departureTime;
- assertEquals(expected, result, msg);
- }
- @Test
- void testNoDestinations() {
- String[] route = {};
- String departureTime = "12:00";
- String expected = "The Train Driver has the day off";
- String result = Kata.arrivalTime(route, departureTime);
- String msg = "Input: " + Arrays.toString(route) + ", " + departureTime;
- assertEquals(expected, result, msg);
- }
- /*-------------------------------TEST CASES---------------------------------*/
- @Test
- void testStaySkyport() {
- String[] route = { "Skyport" };
- String departureTime = "21:30";
- String expected = "22:30";
- String result = Kata.arrivalTime(route, departureTime);
- String msg = "Input: " + Arrays.toString(route) + ", " + departureTime;
- assertEquals(expected, result, msg);
- }
- @Test
- void testOasisNexus() {
- String[] route = { "Oasis", "Nexus" };
- String departureTime = "06:30";
- String expected = "17:20";
- String result = Kata.arrivalTime(route, departureTime);
- String msg = "Input: " + Arrays.toString(route) + ", " + departureTime;
- assertEquals(expected, result, msg);
- }
- @Test
- void testCrystaliumNexus() {
- String[] route = { "Crystalium", "Nexus" };
- String departureTime = "23:50";
- String expected = "08:30";
- String result = Kata.arrivalTime(route, departureTime);
- String msg = "Input: " + Arrays.toString(route) + ", " + departureTime;
- assertEquals(expected, result, msg);
- }
- @Test
- void testDuplicateCities() {
- String[] route = { "Crystalium", "Crystalium", "Oasis", "Oasis" };
- String departureTime = "00:30";
- String expected = "06:25";
- String result = Kata.arrivalTime(route, departureTime);
- String msg = "Input: " + Arrays.toString(route) + ", " + departureTime;
- assertEquals(expected, result, msg);
- }
- @Test
- void testDuplicateNexus() {
- String[] route = { "Nexus", "Nexus" };
- String departureTime = "20:15";
- String expected = "01:30";
- String result = Kata.arrivalTime(route, departureTime);
- String msg = "Input: " + Arrays.toString(route) + ", " + departureTime;
- assertEquals(expected, result, msg);
- }
- @RepeatedTest(50)
- void testRandom() {
- Random random = new Random();
- String[] possiblesRoutes = { "Skyport", "Crystalium", "Oasis", "Nexus" };
- int size = random.nextInt(30, 51);
- String[] randomRoute = new String[size];
- for (int i = 0; i < size; i++) {
- randomRoute[i] = possiblesRoutes[random.nextInt(possiblesRoutes.length)];
- }
- int hour = random.nextInt(0, 24);
- int minute = random.nextInt(0, 60);
- String randomDepartureTime = String.format("%02d:%02d", hour, minute);
- String result = Kata.arrivalTime(randomRoute, randomDepartureTime);
- String msg = "Random input: " + Arrays.toString(randomRoute) + ", " + randomDepartureTime;
- assertEquals(arrivalTime(randomRoute, randomDepartureTime), result, msg);
- }
- private static String arrivalTime(final String[] route, final String departureTime) {
- if (route.length == 0)
- return "The Train Driver has the day off";
- LocalTime timeResult = LocalTime.parse(departureTime, DateTimeFormatter.ofPattern("HH:mm"));
- String origin = "Skyport";
- for (int i = 0; i < route.length; i++) {
- String destination = route[i];
- Map<String, double[]> destinationMap = tabla.get(origin);
- if (destinationMap != null && destinationMap.containsKey(destination)) {
- double[] times = destinationMap.get(destination);
- timeResult = calculateTime(timeResult, times);
- origin = destination;
- } else if (origin.equals(destination)) {
- timeResult = timeResult.plusHours(1);
- } else {
- String transbordo = "Skyport";
- double[] times = tabla.get(origin).get(transbordo);
- timeResult = calculateTime(timeResult, times);
- origin = transbordo;
- i--;
- }
- }
- return timeResult.format(DateTimeFormatter.ofPattern("HH:mm"));
- }
- private static Map<String, Map<String, double[]>> tabla = new HashMap<String, Map<String, double[]>>() {
- {
- addRecord("Skyport", "Crystalium", 15, 2);
- addRecord("Skyport", "Oasis", 20, 3);
- addRecord("Oasis", "Crystalium", 15, 1.5);
- addRecord("Skyport", "Nexus", 15, 4);
- }
- private void addRecord(final String origin, final String destiny, final double minutesWait,
- final double hoursTravel) {
- putIfAbsent(origin, new HashMap<>());
- get(origin).put(destiny, new double[] { minutesWait, hoursTravel });
- putIfAbsent(destiny, new HashMap<>());
- get(destiny).put(origin, new double[] { minutesWait - 5, hoursTravel });
- }
- };
- private static LocalTime calculateTime(final LocalTime currentTime, final double[] times) {
- int minutes = (int) times[0];
int hours = (int) times[1];int remainingMinutes = (int) ((times[1] - hours) * 60);- int remainingMinutes = (int) (times[1] * 60);
return currentTime.plusMinutes(minutes).plusHours(hours).plusMinutes(remainingMinutes);- return currentTime.plusMinutes(minutes).plusMinutes(remainingMinutes);
- }
- }
import java.time.LocalTime; import java.time.format.DateTimeFormatter; import java.util.HashMap; import java.util.Map; public class Kata { public static String arrivalTime(final String[] route, final String departureTime) { if (route.length == 0) return "The Train Driver has the day off"; LocalTime timeResult = LocalTime.parse(departureTime, DateTimeFormatter.ofPattern("HH:mm")); String origin = "Skyport"; for (int i = 0; i < route.length; i++) { String destination = route[i]; Map<String, double[]> destinationMap = tabla.get(origin); if (destinationMap != null && destinationMap.containsKey(destination)) { double[] times = destinationMap.get(destination); timeResult = calculateTime(timeResult, times); origin = destination; } else if (origin.equals(destination)) { timeResult = timeResult.plusHours(1); } else { String transfer = "Skyport"; double[] times = tabla.get(origin).get(transfer); timeResult = calculateTime(timeResult, times); origin = transfer; i--; } } return timeResult.format(DateTimeFormatter.ofPattern("HH:mm")); } private static Map<String, Map<String, double[]>> tabla = new HashMap<String, Map<String, double[]>>() { { addRecord("Skyport", "Crystalium", 15, 2); addRecord("Skyport", "Oasis", 20, 3); addRecord("Oasis", "Crystalium", 15, 1.5); addRecord("Skyport", "Nexus", 15, 4); } private void addRecord(final String origin, final String destiny, final double minutesWait, final double hoursTravel) { putIfAbsent(origin, new HashMap<>()); get(origin).put(destiny, new double[] { minutesWait, hoursTravel }); putIfAbsent(destiny, new HashMap<>()); get(destiny).put(origin, new double[] { minutesWait - 5, hoursTravel }); } }; private static LocalTime calculateTime(final LocalTime currentTime, final double[] times) { int minutes = (int) times[0]; int remainingMinutes = (int) (times[1] * 60); return currentTime.plusMinutes(minutes).plusMinutes(remainingMinutes); } }
- import java.time.LocalTime;
- import java.time.format.DateTimeFormatter;
- import java.util.HashMap;
- import java.util.Map;
- public class Kata {
- public static String arrivalTime(final String[] route, final String departureTime) {
- if (route.length == 0)
- return "The Train Driver has the day off";
- LocalTime timeResult = LocalTime.parse(departureTime, DateTimeFormatter.ofPattern("HH:mm"));
- String origin = "Skyport";
- for (int i = 0; i < route.length; i++) {
- String destination = route[i];
- Map<String, double[]> destinationMap = tabla.get(origin);
- if (destinationMap != null && destinationMap.containsKey(destination)) {
- double[] times = destinationMap.get(destination);
- timeResult = calculateTime(timeResult, times);
- origin = destination;
- } else if (origin.equals(destination)) {
- timeResult = timeResult.plusHours(1);
- } else {
- String transfer = "Skyport";
- double[] times = tabla.get(origin).get(transfer);
- timeResult = calculateTime(timeResult, times);
- origin = transfer;
- i--;
- }
- }
- return timeResult.format(DateTimeFormatter.ofPattern("HH:mm"));
- }
- private static Map<String, Map<String, double[]>> tabla = new HashMap<String, Map<String, double[]>>() {
- {
- addRecord("Skyport", "Crystalium", 15, 2);
- addRecord("Skyport", "Oasis", 20, 3);
- addRecord("Oasis", "Crystalium", 15, 1.5);
- addRecord("Skyport", "Nexus", 15, 4);
- }
- private void addRecord(final String origin, final String destiny, final double minutesWait,
- final double hoursTravel) {
- putIfAbsent(origin, new HashMap<>());
- get(origin).put(destiny, new double[] { minutesWait, hoursTravel });
- putIfAbsent(destiny, new HashMap<>());
- get(destiny).put(origin, new double[] { minutesWait - 5, hoursTravel });
- }
- };
- private static LocalTime calculateTime(final LocalTime currentTime, final double[] times) {
- int minutes = (int) times[0];
int hours = (int) times[1];int remainingMinutes = (int) ((times[1] - hours) * 60);- int remainingMinutes = (int) (times[1] * 60);
return currentTime.plusMinutes(minutes).plusHours(hours).plusMinutes(remainingMinutes);- return currentTime.plusMinutes(minutes).plusMinutes(remainingMinutes);
- }
- }
import java.time.LocalTime; import java.time.format.DateTimeFormatter; import java.util.HashMap; import java.util.Map; public class Kata { public static String arrivalTime(final String[] route, final String departureTime) { if (route.length == 0) return "Pepe has the day off"; LocalTime timeResult = LocalTime.parse(departureTime, DateTimeFormatter.ofPattern("HH:mm")); String origin = "Skyport"; for (int i = 0; i < route.length; i++) { String destination = route[i]; Map<String, double[]> destinationMap = tabla.get(origin); if (destinationMap != null && destinationMap.containsKey(destination)) { double[] times = destinationMap.get(destination); timeResult = calculateTime(timeResult, times); origin = destination; } else if (origin.equals(destination)) { timeResult = timeResult.plusHours(1); } else { String transfer = "Skyport"; double[] times = tabla.get(origin).get(transfer); timeResult = calculateTime(timeResult, times); origin = transfer; i--; } } return timeResult.format(DateTimeFormatter.ofPattern("HH:mm")); } private static Map<String, Map<String, double[]>> tabla = new HashMap<String, Map<String, double[]>>() { { addRecord("Skyport", "Crystalium", 15, 2); addRecord("Skyport", "Oasis", 20, 3); addRecord("Oasis", "Crystalium", 15, 1.5); addRecord("Skyport", "Nexus", 15, 4); } private void addRecord(final String origin, final String destiny, final double minutesWait, final double hoursTravel) { putIfAbsent(origin, new HashMap<>()); get(origin).put(destiny, new double[] { minutesWait, hoursTravel }); putIfAbsent(destiny, new HashMap<>()); get(destiny).put(origin, new double[] { minutesWait - 5, hoursTravel }); } }; private static LocalTime calculateTime(final LocalTime currentTime, final double[] times) { int minutes = (int) times[0]; int hours = (int) times[1]; int remainingMinutes = (int) ((times[1] - hours) * 60); return currentTime.plusMinutes(minutes).plusHours(hours).plusMinutes(remainingMinutes); } }
- import java.time.LocalTime;
- import java.time.format.DateTimeFormatter;
- import java.util.HashMap;
- import java.util.Map;
- public class Kata {
public static String arrivalTime(final String[] route, final String departureTime) {- public static String arrivalTime(final String[] route, final String departureTime) {
- if (route.length == 0)
- return "Pepe has the day off";
- LocalTime timeResult = LocalTime.parse(departureTime, DateTimeFormatter.ofPattern("HH:mm"));
String origin = "Madrid";- String origin = "Skyport";
- for (int i = 0; i < route.length; i++) {
- String destination = route[i];
- Map<String, double[]> destinationMap = tabla.get(origin);
- if (destinationMap != null && destinationMap.containsKey(destination)) {
- double[] times = destinationMap.get(destination);
- timeResult = calculateTime(timeResult, times);
- origin = destination;
- } else if (origin.equals(destination)) {
- timeResult = timeResult.plusHours(1);
- } else {
String transbordo = "Madrid";double[] times = tabla.get(origin).get(transbordo);- String transfer = "Skyport";
- double[] times = tabla.get(origin).get(transfer);
- timeResult = calculateTime(timeResult, times);
origin = transbordo;- origin = transfer;
- i--;
- }
- }
- return timeResult.format(DateTimeFormatter.ofPattern("HH:mm"));
- }
- private static Map<String, Map<String, double[]>> tabla = new HashMap<String, Map<String, double[]>>() {
- {
addRecord("Madrid", "Barcelona", 15, 2);addRecord("Madrid", "Valencia", 20, 3);addRecord("Valencia", "Barcelona", 15, 1.5);addRecord("Madrid", "Cadiz", 15, 4);- addRecord("Skyport", "Crystalium", 15, 2);
- addRecord("Skyport", "Oasis", 20, 3);
- addRecord("Oasis", "Crystalium", 15, 1.5);
- addRecord("Skyport", "Nexus", 15, 4);
- }
- private void addRecord(final String origin, final String destiny, final double minutesWait,
- final double hoursTravel) {
- putIfAbsent(origin, new HashMap<>());
- get(origin).put(destiny, new double[] { minutesWait, hoursTravel });
- putIfAbsent(destiny, new HashMap<>());
- get(destiny).put(origin, new double[] { minutesWait - 5, hoursTravel });
- }
- };
- private static LocalTime calculateTime(final LocalTime currentTime, final double[] times) {
- int minutes = (int) times[0];
- int hours = (int) times[1];
- int remainingMinutes = (int) ((times[1] - hours) * 60);
- return currentTime.plusMinutes(minutes).plusHours(hours).plusMinutes(remainingMinutes);
- }
- }
import org.junit.jupiter.api.RepeatedTest; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; import java.time.LocalTime; import java.time.format.DateTimeFormatter; import java.util.Arrays; import java.util.HashMap; import java.util.Map; import java.util.Random; class SolutionTest { /*-----------------------------SAMPLE TEST CASES----------------------------*/ @Test void testSingleDestination() { String[] route = { "Crystalium" }; String departureTime = "10:00"; String expected = "12:15"; String result = Kata.arrivalTime(route, departureTime); String msg = "Input: " + Arrays.toString(route) + ", " + departureTime; assertEquals(expected, result, msg); } @Test void testMultipleDestinations() { String[] route = { "Crystalium", "Skyport", "Oasis" }; String departureTime = "10:00"; String expected = "17:45"; String result = Kata.arrivalTime(route, departureTime); String msg = "Input: " + Arrays.toString(route) + ", " + departureTime; assertEquals(expected, result, msg); } @Test void testDepartingFromMidnight() { String[] route = { "Nexus", "Skyport", "Oasis" }; String departureTime = "21:30"; String expected = "09:15"; String result = Kata.arrivalTime(route, departureTime); String msg = "Input: " + Arrays.toString(route) + ", " + departureTime; assertEquals(expected, result, msg); } @Test void testNoDestinations() { String[] route = {}; String departureTime = "12:00"; String expected = "Pepe has the day off"; String result = Kata.arrivalTime(route, departureTime); String msg = "Input: " + Arrays.toString(route) + ", " + departureTime; assertEquals(expected, result, msg); } /*-------------------------------TEST CASES---------------------------------*/ @Test void testStaySkyport() { String[] route = { "Skyport" }; String departureTime = "21:30"; String expected = "22:30"; String result = Kata.arrivalTime(route, departureTime); String msg = "Input: " + Arrays.toString(route) + ", " + departureTime; assertEquals(expected, result, msg); } @Test void testOasisNexus() { String[] route = { "Oasis", "Nexus" }; String departureTime = "06:30"; String expected = "17:20"; String result = Kata.arrivalTime(route, departureTime); String msg = "Input: " + Arrays.toString(route) + ", " + departureTime; assertEquals(expected, result, msg); } @Test void testCrystaliumNexus() { String[] route = { "Crystalium", "Nexus" }; String departureTime = "23:50"; String expected = "08:30"; String result = Kata.arrivalTime(route, departureTime); String msg = "Input: " + Arrays.toString(route) + ", " + departureTime; assertEquals(expected, result, msg); } @Test void testDuplicateCities() { String[] route = { "Crystalium", "Crystalium", "Oasis", "Oasis" }; String departureTime = "00:30"; String expected = "06:25"; String result = Kata.arrivalTime(route, departureTime); String msg = "Input: " + Arrays.toString(route) + ", " + departureTime; assertEquals(expected, result, msg); } @Test void testDuplicateNexus() { String[] route = { "Nexus", "Nexus" }; String departureTime = "20:15"; String expected = "01:30"; String result = Kata.arrivalTime(route, departureTime); String msg = "Input: " + Arrays.toString(route) + ", " + departureTime; assertEquals(expected, result, msg); } @RepeatedTest(50) void testRandom() { Random random = new Random(); String[] possiblesRoutes = { "Skyport", "Crystalium", "Oasis", "Nexus" }; int size = random.nextInt(30, 51); String[] randomRoute = new String[size]; for (int i = 0; i < size; i++) { randomRoute[i] = possiblesRoutes[random.nextInt(possiblesRoutes.length)]; } int hour = random.nextInt(0, 24); int minute = random.nextInt(0, 60); String randomDepartureTime = String.format("%02d:%02d", hour, minute); String result = Kata.arrivalTime(randomRoute, randomDepartureTime); String msg = "Random input: " + Arrays.toString(randomRoute) + ", " + randomDepartureTime; assertEquals(arrivalTime(randomRoute, randomDepartureTime), result, msg); } private static String arrivalTime(final String[] route, final String departureTime) { if (route.length == 0) return "Pepe has the day off"; LocalTime timeResult = LocalTime.parse(departureTime, DateTimeFormatter.ofPattern("HH:mm")); String origin = "Skyport"; for (int i = 0; i < route.length; i++) { String destination = route[i]; Map<String, double[]> destinationMap = tabla.get(origin); if (destinationMap != null && destinationMap.containsKey(destination)) { double[] times = destinationMap.get(destination); timeResult = calculateTime(timeResult, times); origin = destination; } else if (origin.equals(destination)) { timeResult = timeResult.plusHours(1); } else { String transbordo = "Skyport"; double[] times = tabla.get(origin).get(transbordo); timeResult = calculateTime(timeResult, times); origin = transbordo; i--; } } return timeResult.format(DateTimeFormatter.ofPattern("HH:mm")); } private static Map<String, Map<String, double[]>> tabla = new HashMap<String, Map<String, double[]>>() { { addRecord("Skyport", "Crystalium", 15, 2); addRecord("Skyport", "Oasis", 20, 3); addRecord("Oasis", "Crystalium", 15, 1.5); addRecord("Skyport", "Nexus", 15, 4); } private void addRecord(final String origin, final String destiny, final double minutesWait, final double hoursTravel) { putIfAbsent(origin, new HashMap<>()); get(origin).put(destiny, new double[] { minutesWait, hoursTravel }); putIfAbsent(destiny, new HashMap<>()); get(destiny).put(origin, new double[] { minutesWait - 5, hoursTravel }); } }; private static LocalTime calculateTime(final LocalTime currentTime, final double[] times) { int minutes = (int) times[0]; int hours = (int) times[1]; int remainingMinutes = (int) ((times[1] - hours) * 60); return currentTime.plusMinutes(minutes).plusHours(hours).plusMinutes(remainingMinutes); } }
- import org.junit.jupiter.api.RepeatedTest;
- import org.junit.jupiter.api.Test;
- import static org.junit.jupiter.api.Assertions.assertEquals;
- import java.time.LocalTime;
- import java.time.format.DateTimeFormatter;
- import java.util.Arrays;
- import java.util.HashMap;
- import java.util.Map;
- import java.util.Random;
- class SolutionTest {
- /*-----------------------------SAMPLE TEST CASES----------------------------*/
- @Test
- void testSingleDestination() {
String[] route = { "Barcelona" };- String[] route = { "Crystalium" };
- String departureTime = "10:00";
- String expected = "12:15";
- String result = Kata.arrivalTime(route, departureTime);
- String msg = "Input: " + Arrays.toString(route) + ", " + departureTime;
- assertEquals(expected, result, msg);
- }
- @Test
- void testMultipleDestinations() {
String[] route = { "Barcelona", "Madrid", "Valencia" };- String[] route = { "Crystalium", "Skyport", "Oasis" };
- String departureTime = "10:00";
- String expected = "17:45";
- String result = Kata.arrivalTime(route, departureTime);
- String msg = "Input: " + Arrays.toString(route) + ", " + departureTime;
- assertEquals(expected, result, msg);
- }
- @Test
- void testDepartingFromMidnight() {
String[] route = { "Cadiz", "Madrid", "Valencia" };- String[] route = { "Nexus", "Skyport", "Oasis" };
- String departureTime = "21:30";
- String expected = "09:15";
- String result = Kata.arrivalTime(route, departureTime);
- String msg = "Input: " + Arrays.toString(route) + ", " + departureTime;
- assertEquals(expected, result, msg);
- }
- @Test
- void testNoDestinations() {
- String[] route = {};
- String departureTime = "12:00";
- String expected = "Pepe has the day off";
- String result = Kata.arrivalTime(route, departureTime);
- String msg = "Input: " + Arrays.toString(route) + ", " + departureTime;
- assertEquals(expected, result, msg);
- }
- /*-------------------------------TEST CASES---------------------------------*/
- @Test
void testStayMadrid() {String[] route = { "Madrid" };- void testStaySkyport() {
- String[] route = { "Skyport" };
- String departureTime = "21:30";
- String expected = "22:30";
- String result = Kata.arrivalTime(route, departureTime);
- String msg = "Input: " + Arrays.toString(route) + ", " + departureTime;
- assertEquals(expected, result, msg);
- }
- @Test
void testValenciaCadiz() {String[] route = { "Valencia", "Cadiz" };- void testOasisNexus() {
- String[] route = { "Oasis", "Nexus" };
- String departureTime = "06:30";
- String expected = "17:20";
- String result = Kata.arrivalTime(route, departureTime);
- String msg = "Input: " + Arrays.toString(route) + ", " + departureTime;
- assertEquals(expected, result, msg);
- }
- @Test
void testBarcelonaCadiz() {String[] route = { "Barcelona", "Cadiz" };- void testCrystaliumNexus() {
- String[] route = { "Crystalium", "Nexus" };
- String departureTime = "23:50";
- String expected = "08:30";
- String result = Kata.arrivalTime(route, departureTime);
- String msg = "Input: " + Arrays.toString(route) + ", " + departureTime;
- assertEquals(expected, result, msg);
- }
- @Test
- void testDuplicateCities() {
String[] route = { "Barcelona", "Barcelona", "Valencia", "Valencia" };- String[] route = { "Crystalium", "Crystalium", "Oasis", "Oasis" };
- String departureTime = "00:30";
- String expected = "06:25";
- String result = Kata.arrivalTime(route, departureTime);
- String msg = "Input: " + Arrays.toString(route) + ", " + departureTime;
- assertEquals(expected, result, msg);
- }
- @Test
void testDuplicateCadiz() {String[] route = { "Cadiz", "Cadiz" };- void testDuplicateNexus() {
- String[] route = { "Nexus", "Nexus" };
- String departureTime = "20:15";
- String expected = "01:30";
- String result = Kata.arrivalTime(route, departureTime);
- String msg = "Input: " + Arrays.toString(route) + ", " + departureTime;
- assertEquals(expected, result, msg);
- }
- @RepeatedTest(50)
- void testRandom() {
- Random random = new Random();
String[] possiblesRoutes = { "Madrid", "Barcelona", "Valencia", "Cadiz" };- String[] possiblesRoutes = { "Skyport", "Crystalium", "Oasis", "Nexus" };
- int size = random.nextInt(30, 51);
- String[] randomRoute = new String[size];
- for (int i = 0; i < size; i++) {
- randomRoute[i] = possiblesRoutes[random.nextInt(possiblesRoutes.length)];
- }
- int hour = random.nextInt(0, 24);
- int minute = random.nextInt(0, 60);
- String randomDepartureTime = String.format("%02d:%02d", hour, minute);
- String result = Kata.arrivalTime(randomRoute, randomDepartureTime);
- String msg = "Random input: " + Arrays.toString(randomRoute) + ", " + randomDepartureTime;
- assertEquals(arrivalTime(randomRoute, randomDepartureTime), result, msg);
- }
private static String arrivalTime(final String[] route, final String departureTime) {- private static String arrivalTime(final String[] route, final String departureTime) {
- if (route.length == 0)
- return "Pepe has the day off";
- LocalTime timeResult = LocalTime.parse(departureTime, DateTimeFormatter.ofPattern("HH:mm"));
String origin = "Madrid";- String origin = "Skyport";
- for (int i = 0; i < route.length; i++) {
- String destination = route[i];
- Map<String, double[]> destinationMap = tabla.get(origin);
- if (destinationMap != null && destinationMap.containsKey(destination)) {
- double[] times = destinationMap.get(destination);
- timeResult = calculateTime(timeResult, times);
- origin = destination;
- } else if (origin.equals(destination)) {
- timeResult = timeResult.plusHours(1);
- } else {
String transbordo = "Madrid";- String transbordo = "Skyport";
- double[] times = tabla.get(origin).get(transbordo);
- timeResult = calculateTime(timeResult, times);
- origin = transbordo;
- i--;
- }
- }
- return timeResult.format(DateTimeFormatter.ofPattern("HH:mm"));
- }
- private static Map<String, Map<String, double[]>> tabla = new HashMap<String, Map<String, double[]>>() {
- {
addRecord("Madrid", "Barcelona", 15, 2);addRecord("Madrid", "Valencia", 20, 3);addRecord("Valencia", "Barcelona", 15, 1.5);addRecord("Madrid", "Cadiz", 15, 4);- addRecord("Skyport", "Crystalium", 15, 2);
- addRecord("Skyport", "Oasis", 20, 3);
- addRecord("Oasis", "Crystalium", 15, 1.5);
- addRecord("Skyport", "Nexus", 15, 4);
- }
- private void addRecord(final String origin, final String destiny, final double minutesWait,
- final double hoursTravel) {
- putIfAbsent(origin, new HashMap<>());
- get(origin).put(destiny, new double[] { minutesWait, hoursTravel });
- putIfAbsent(destiny, new HashMap<>());
- get(destiny).put(origin, new double[] { minutesWait - 5, hoursTravel });
- }
- };
- private static LocalTime calculateTime(final LocalTime currentTime, final double[] times) {
- int minutes = (int) times[0];
- int hours = (int) times[1];
- int remainingMinutes = (int) ((times[1] - hours) * 60);
- return currentTime.plusMinutes(minutes).plusHours(hours).plusMinutes(remainingMinutes);
- }
- }