Menu
Question Index
...


Write a program to get the highest speed between any two stations in the train journey. The result should be a formatted string as shown below in requirements.

Input (List) 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]] Highest Speed is 90.00 Kmph between 'Tenali Junction' and 'Vijayawada'
[[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]] Highest Speed is 1928.57 Kmph between 'Peddapalli' and 'Ramgundam'
[[Kavali-null-20:10-0], [Nellore-21:20-21:30-35], [Gudur-22:30-22: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]] Highest Speed is 144.00 Kmph between 'Chittoor' and 'Kolar'

class GetHighestSpeed

{    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(getHighestSpeed(journey));

    }


private static String getHighestSpeed(ArrayList<Destination> journey) {
//Write code here to get the highest speed of the train journey and its corresponding destinations
}

//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 Formatter

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App