Advertisement
Guest User

Untitled

a guest
Nov 23rd, 2014
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. public static void ShortestPath(String departure, String arrival, org.jgrapht.Graph<String, FlightInfo> f) throws ParseException {
  2. DijkstraShortestPath<String, FlightInfo> flightPath = new DijkstraShortestPath<>(f, departure, arrival);
  3.  
  4. int noOfFlights = (int) flightPath.getPathLength();
  5. int totalCost = 0;
  6.  
  7. for (int i = 0; i < noOfFlights; i++) {
  8. int cost = flightPath.getPathEdgeList().get(i).getCost();
  9. totalCost = totalCost + cost;
  10.  
  11. time = flightPath.getPathEdgeList().get(i).calculateFlightDuration();
  12. }
  13.  
  14. //Error: only gets the value of the last list
  15. System.out.println("Total Time of Flight: " + time);
  16.  
  17. public FlightInfo(String departTime, String arriveTime){
  18. this.departTime = departTime;
  19. this.arriveTime = arriveTime;
  20. }
  21. public String calculateFlightDuration() throws ParseException {
  22. DateFormat form = new SimpleDateFormat("hh:mm");
  23. Date a = form.parse(departTime);
  24. Date b = form.parse(arriveTime);
  25.  
  26. hh = (b.getTime() - a.getTime()) / 3600000;
  27. mm = ((b.getTime() - a.getTime()) % 3600000) / 60000;
  28.  
  29. String dur = String.valueOf(hh) + " hours and " + String.valueOf(mm) + " minutes";
  30. return dur;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement