Menu
Question Index
...


Write a program to get the train location. The station, arrival time, departure time and the distance from the previous station are given.

Input (List, String) Output (String)
[[Hyderabad-null-18:30-0.0], [Secunderabad-18:58-19:05-9.2], [Kazipet Junc-21:00-21:05-130.8], [Warangal Junc-21:27-21:29-10.2], [Mahabubabad-22:30-22:31-60.0], [Dornakal Junc-22:49-22:50-24.4], [Khammam-23:10-23:12-23.0], [Vijayawada Junc-01:15-01:25-100.4], [Tenali Junc-01:56-01:57-31.3], [Chirala-02:41-02:43-57.7], [Ongole-03:18-03:20-49.3], [Kavali-03:49-03:50-66.0], [Nellore-04:23-04:24-50.8]], 00:00 At '00:00' left 'Khammam', 61.22 km from 'Vijayawada Junc'
[[Kavali-null-08:10-0], [Nellore-09:20-09:30-35], [Gudur-10:30-10:40-35], [Tirupati-00:20-00:30-180], [Chittoor-01:30-01:35-30], [Kolar-02:00-02:10-60], [Bangalore-05:40-null-98]]",02:05 At '02:05' the train is at 'Kolar'
[[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]], 07:00 At '07:00' left 'Ulavapadu', 3.75 km from 'Singarayakonda'
[[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:03-null-26.0]], 23:00  At '23:00' left 'Akanapet', 3.39 km from 'Kamareddy'

class GetTrainLocation

{    public static void main(String s[])
    {
        ArrayList journey = new ArrayList();
        journey.add(new Destination("Hyderabad", null, "18:30", 0));
        journey.add(new Destination("Secunderabad", "18:58", "19:05", 9.2));
        journey.add(new Destination("Kazipet Junc", "21:00", "21:05", 130.8));
        journey.add(new Destination("Warangal Junc", "21:27", "21:29", 10.2));
        journey.add(new Destination("Mahabubabad", "22:30", "22:31", 60.0));
        journey.add(new Destination("Dornakal Junc", "22:49", "22:50", 24.4));
        journey.add(new Destination("Khammam", "23:10", "23:12", 23.0));
        journey.add(new Destination("Vijayawada Junc", "01:15", "01:25", 100.40));
        journey.add(new Destination("Tenali Junc", "01:56", "01:57", 31.3));
        journey.add(new Destination("Chirala", "02:41", "02:43", 57.7));
        journey.add(new Destination("Ongole", "03:18", "03:20", 49.3));
        journey.add(new Destination("Kavali", "03:49", "03:50", 66.0));
        journey.add(new Destination("Nellore", "04:23", null, 50.8));
        System.out.println(getTrainLocation(journey, "00:00"));

    }


private static String getTrainLocation(ArrayList<Destination> journey, String time) {
//Write code here to get the train location at the given time
}
}
class Destination {

String cityName;
String arrivalTime;
String depatureTime;
double kiloMeters;

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

//If required, write any additional methods here
@Override
public String toString() {
return "[" + cityName + "-" + arrivalTime + "-" + depatureTime + "-" + kiloMeters + "]";
}
}

Doubts

Problems

Topic: Java Formatter

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App