Get travel time between two stations - Java Quiz Question



Write a program to get the travel time between the given two stations. The result should be a formatted string as shown below in requirements.

Input (List, String, String) Output (String)
[[Chennai-null-18:00-0], [Gudur-20:00-20:20-100], [Nellore-21:00-21:10-25], [Kavali-21:30-21:35-20], [Ongole-22:30-22:40-40], [Chirala -23:30-23:35-31], [Tenali Junction-00:30-00:35-31] [Vijayawada-01:05-01:35-45], [Hyderabad-03:20-03:50-100], [Karimnagar-05:35-null-60]], 'Chirala', 'Tenali Junction' The travel time from 'Chirala' to 'Tenali Junction' is 55 mins
[[Hyderabad-null-08:00-0], [Bhongir-08:59-09:00-47], [Aler-09:19-09:20-70], [Jangaon-09:29-09:30-84], [Ghanpur-09:53-09:54-112], [Kazipet Jn-10:28-10:30-132], [Jamikunta-10:58-10:59-168], [Odela-11:24-11:25-188], [Peddapalli-11:34-11:35-208], [Ramgundam-11:42-11:43-225], [Mancheral-11:55-11:56-239], [Belampalli-12:21-12:22-258], [Sirpur Kagazngr-13:45-null-297]], 'Hyderabad', 'Sirpur Kagazngr' The travel time from 'Hyderabad' to 'Sirpur Kagazngr' is 5hrs 45 mins
[[Secunderabad Junc-null-21:13-0.0], [Malkajgiri-21:21-21:22-3.0], [Bolarum-21:44-21:45-11.0], [Mirzapali-22:32-22:33-58.0], [Akanapet-22:39-22:40-10.0], [Kamareddy-23:40-null-26.0]], 'Akanapet', 'Kamareddy' The travel time from 'Akanapet' to 'Kamareddy' is 1hr 

class GetTravelTimeBetweenTwoStations

{    public static void main(String s[])
    {
        ArrayList journey = new ArrayList();
        journey.add(new Destination("Chennai", null, "18:00", 0));
        journey.add(new Destination("Gudur", "20:00", "20:20", 100));
        journey.add(new Destination("Nellore", "21:00", "21:10", 25));
        journey.add(new Destination("Kavali", "21:30", "21:35", 20));
        journey.add(new Destination("Ongole", "22:30", "22:40", 40));
        journey.add(new Destination("Chirala", "23:30", "23:35", 31));
        journey.add(new Destination("Tenali Junction", "00:30", "00:35", 31));
        journey.add(new Destination("Vijayawada", "01:05", "01:35", 45));
        journey.add(new Destination("Hyderabad", "03:20", "03:50", 100));
        journey.add(new Destination("Karimnagar", "05:35", null, 60));
        System.out.println(getTime(journey, "Chirala", "Tenali Junction"));

    }


private static String getTime(ArrayList<Destination> journey, String sourceCity, String destinationCity) {
//Write code here to get the time for to reach from source city to destination city
}

//If required, write any additional methods here.
}
class Destination {

String cityName;
String arrivalTime;
String depatureTime;
int kiloMeters;

public Destination(String cityName, String arrivalTime, String depatureTime, int kiloMeters) {
this.cityName = cityName;
this.arrivalTime = arrivalTime;
this.depatureTime = depatureTime;
this.kiloMeters = kiloMeters;
}

@Override
public String toString() {
return "[" + cityName + "-" + arrivalTime + "-" + depatureTime + "-" + kiloMeters + "]";
}
}