info@meritcampus.com    +91-85006-22255
...

Given the train journey details and details of various passengers, identify those who got on the train. Assume that the train journey is always in a single day.

Input (List, List) Output (List)
[[Chennai-null-15:00-0], [Gudur-17:00-17:10-100], [Nellore-18:30-19:00-25], [Kavali-20:00-20:05-20], [Ongole-21:30-21:40-40], [Chirala -22:30-22:35-31], [Tenali Junction-23:00-23:01-31]], [[Ramu-Chennai-14:30], [Sreenu-Kavali-21:00], [Suman-Chirala-22:36], [Hema-Ongole-21:00], [Kalyan-Chirala-22:32]] [Ramu, Hema, Kalyan]
[[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]], [[Krishna-Hyderabad-06:00], [Varma-Bhongir-09:10], [Sirisha-Jangaon-09:30], [Swapna-Kazipet Jn-10:30], [Shekar-Odela-11:30], [Priya-Peddapalli-11:30], [Mounika-Mancheral-12:30], [Bhargav-Belampalli-11:30]] [Krishna, Sirisha, Swapna, Priya, Bhargav]

``` import java.util.*; class IdentifyListOfPersonsOnTrain {     public static void main(String s[])    {        ArrayList<Destination> journey = new ArrayList<Destination>();        journey.add(new Destination("Chennai", null, "15:00", 0));        journey.add(new Destination("Gudur", "17:00", "17:10", 100));        journey.add(new Destination("Nellore", "18:30", "19:00", 25));        journey.add(new Destination("Kavali", "20:00", "20:05", 20));        journey.add(new Destination("Ongole", "21:30", "21:40", 40));        journey.add(new Destination("Chirala", "22:30", "22:35", 31));        journey.add(new Destination("Tenali Junction", "23:00", null, 31));        ArrayList<Passenger> passengers = new ArrayList<Passenger>();        passengers.add(new Passenger("Ramu", "Chennai", "14:30"));        passengers.add(new Passenger("Sreenu", "Kavali", "21:00"));        passengers.add(new Passenger("Suman", "Chirala", "22:36"));        passengers.add(new Passenger("Hema", "Ongole", "21:00"));        passengers.add(new Passenger("Kalyan", "Chirala", "22:32"));        ArrayList<String> result = passengersWhoGotOnTrain(journey, passengers);        System.out.println("The list of passengers who got on the train is : " + result);    }     private static ArrayList<String> passengersWhoGotOnTrain(ArrayList<Destination> journey, ArrayList<Passenger> passengers) { ```
```     }      ```
``` } 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 + "]"; } } class Passenger { String name; String cityName; String arrivalTime; public Passenger(String name, String cityName, String arrivalTime) { this.name = name; this.cityName = cityName; this.arrivalTime = arrivalTime; } @Override public String toString() { return "[" + name + "-" + cityName + "-" + arrivalTime + "]"; } } ```

Topic: Java ArrayList

0
Wrong
Score more than 2 points