Menu
Question Index
...


Write a program to get the total waiting 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]], 'Chennai', 'Karimnagar' Total waiting time from 'Chennai' to 'Karimnagar' is 1hr 55 mins
[[Kavali-null-20:10-0], [Nellore-21:20-21:30-35], [Gudur-23:30-00:40-35], [Tirupati-01:20-01:55-180], [Chittoor-03:30-03:55-30], [Kolar-05:00-06:10-60], [Bangalore-08:40-null-98]], 'Tirupati', 'Chittoor' Total waiting time from 'Tirupati' to 'Chittoor' is 1hr 
[[Nellore-null-21:30-0], [Ongole-22:30-23:00-100], [Guntur-23:30-00:30-100], [Vijayawada-03:10-null-100]], 'Ongole', 'Guntur' Total waiting time from 'Ongole' to 'Guntur' is 1hr 30 mins

class GetWaitingTimeBetweenTwoStations

{    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, "Chennai", "Karimnagar"));

    }


private static String getTime(ArrayList<Destination> journey, String sourceCity, String destinationCity) {
//Write code here to get the total waiting time, 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 + "]";
}
}

Doubts

Problems

Topic: Java ArrayList

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App