SHARE
TWEET

Untitled

a guest Dec 10th, 2018 404 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class FlightStopsCounter {
  2.     ArrayList<Flight> flights;
  3.     int max_air_time;
  4.    
  5.     public FlightStopsCounter(ArrayList<Flight> flights, int max_air_time) {
  6.         super();
  7.         this.flights = flights;
  8.         this.max_air_time = max_air_time;
  9.     }
  10.  
  11.     public Date getDateByAppending(int minutes, Date date) {
  12.         long ONE_MINUTE_IN_MILLIS = 60000;
  13.         Date endDate = new Date(date.getTime() + (minutes*ONE_MINUTE_IN_MILLIS));
  14.         return endDate;
  15.     }
  16.        
  17.    
  18.     public int getMaxNumberOfSteps(ArrayList<Flight> flights, int accum,  Date date_point, String origin) {
  19.         int max_count = 0;
  20.         Date filter_date = getDateByAppending(2880,date_point);
  21.         int i = 0;
  22.         while(i < flights.size() && flights.get(i).getReal_time().before(filter_date)) {
  23.             Flight flight = flights.get(i);
  24.             if(flight.getOrigin.equals(origin){
  25.                 Date copy = getDateByAppending(flight.air_time, flight.real_time);
  26.                 ArrayList<Flight> filter_flights = new ArrayList<Flight>(flights.subList(i+1, flights.size()-1));
  27.                 int count = getMaxNumberOfSteps(filter_flights, accum + 2, copy, origin);
  28.                 if (count > max_count) {
  29.                     max_count = count;
  30.                 }
  31.             }
  32.             ++i;           
  33.         }
  34.         return max_count;
  35.     }
  36.    
  37.    
  38.     public static int calculate_max_air_time(ArrayList<Flight> flights){
  39.         int max = 0;
  40.         for(int i = 0; i < flights.size(); ++i) {
  41.             if(flights.get(i).air_time > max) {
  42.                 max = flights.get(i).getAir_time();
  43.             }
  44.         }
  45.         return max;
  46.     }
  47.  
  48.    
  49.     public static void main(String[] args)
  50.     {
  51.         ArrayList<Flight> flights = reader("C:\\Users\\Maria\\eclipse-workspace\\MyFirstProject\\flights.csv");
  52.         int max_air_time = calculate_max_air_time(flights);
  53.         FlightStopsCounter flightStopsCounter = new FlightStopsCounter(flights, max_air_time);
  54.         flightStopsCounter.getMaxNumberOfSteps(flights,0, flights.get(0).getReal_time(), flights.get(0).getOrigin());
  55.         System.out.println(flightStopsCounter.getMaxNumberOfSteps(flights,0, flights.get(0).getReal_time(), flights.get(0).getOrigin()));
  56.  
  57.     }
  58.  
  59.  
  60. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top