Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void ShortestPath(String departure, String arrival, org.jgrapht.Graph<String, FlightInfo> f) throws ParseException {
- DijkstraShortestPath<String, FlightInfo> flightPath = new DijkstraShortestPath<>(f, departure, arrival);
- int noOfFlights = (int) flightPath.getPathLength();
- int totalCost = 0;
- for (int i = 0; i < noOfFlights; i++) {
- int cost = flightPath.getPathEdgeList().get(i).getCost();
- totalCost = totalCost + cost;
- time = flightPath.getPathEdgeList().get(i).calculateFlightDuration();
- }
- //Error: only gets the value of the last list
- System.out.println("Total Time of Flight: " + time);
- public FlightInfo(String departTime, String arriveTime){
- this.departTime = departTime;
- this.arriveTime = arriveTime;
- }
- public String calculateFlightDuration() throws ParseException {
- DateFormat form = new SimpleDateFormat("hh:mm");
- Date a = form.parse(departTime);
- Date b = form.parse(arriveTime);
- hh = (b.getTime() - a.getTime()) / 3600000;
- mm = ((b.getTime() - a.getTime()) % 3600000) / 60000;
- String dur = String.valueOf(hh) + " hours and " + String.valueOf(mm) + " minutes";
- return dur;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement