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

Write a program to find the average speed of the train. Average speed is calculated using the time taken from starting point to the end point and the total distance covered.

Input (List) Output (double)
[[Kavali-null-06:10-0], [Tettu-06:20-06:25-2], [Ulavapadu-06:50-06:55-10), [Singarayakonda-07:15-07:20-5], [Ongole-08:00-null-15]] 17.45455
[[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]] 39.02158
[[Delhi-null-17:32-0], [Mathura Jun-19:44-19:46-141], [Agra Cantonment-20:35-20:38-54], [Gwalior-22:07-22:10-118], [Jhansi Junction-23:32-23:44-97], [Bhopal Junction-03:24-03:29-291], [Nagpur-09:37-09:47-389], [Chandrapur-12:26-12:28-197], [Balharshah-13:23-13:33-14], [Sirpur Kagaznagar-14:18-14:20-70], [Belampalli-14:53-14:55-38], [Mancheral-15:14-15:16-20], [Ramagundam-15:20-15:22-14], [Kazipet Junction-16:45-16:47-92], [Secunderabad Junction-19:14-19:19-132], [Hyderabad Deccan-19:52-null-10]] 63.68354

``` class GetAverageSpeed {    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("The average speed of the train is : " + getAverageSpeed(journey));    } private static double getAverageSpeed(ArrayList<Destination> journey) { //Write code here to get the average speed of the train } //Write additional methods here if required } class Destination { String cityName; String arrivalTime; String depatureTime; int kiloMeters; public Destination(String cityName, String arrivalTime, String depatureTime, Integer kiloMeters) { this.cityName = cityName; this.arrivalTime = arrivalTime; this.depatureTime = depatureTime; this.kiloMeters = kiloMeters; } @Override public String toString() { return "[" + cityName + "-" + arrivalTime + "-" + depatureTime + "-" + kiloMeters + "]"; } } ```

Topic: Java ArrayList

0
Wrong
Score more than 2 points