Пример #1
0
  /** Calculates the wait time between all the flights and adds it to the total travel time. */
  public void calculateWaitTime() {
    if (this.flights.size() >= 2) {
      int i = 0;
      int j = 1;
      Flight f1 = this.flights.get(i);
      Flight f2 = this.flights.get(j);
      Integer waitTime;
      boolean done = false;

      do {
        Calendar f1Arrive = f1.getArrivalDateTime();
        Calendar f2Depart = f2.getDepartureDateTime();

        // subtract departure and arrival time
        waitTime = (int) ((f2Depart.getTimeInMillis() - f1Arrive.getTimeInMillis()) / (1000 * 60));
        // Add waittime to total travel time.
        this.waitTimes.add(waitTime);
        this.totalTravelTime += waitTime;

        // end when we've calculate all waittimes
        if (j == this.flights.size() - 1) {
          done = true;
        } else {
          i++;
          j++;
          f1 = this.flights.get(i);
          f2 = this.flights.get(j);
        }
      } while (!done);
    }
  }
  /**
   * returns a string representation of the Itinerary.
   *
   * @return string representation of the Itinerary.
   */
  @Override
  public String toString() {
    String returnString = "";
    int time = this.getCreatedItineraryTime();
    double cost = this.getCreatedItineraryCost();
    int hours = time / 60;
    int minutes = time % 60;

    for (Flight flight : this.flights) {
      returnString +=
          flight.getFlightNum()
              + ","
              + flight.getDepartureDateTime()
              + ","
              + flight.getArrivalDateTime()
              + ","
              + flight.getAirline()
              + ","
              + flight.getOrigin()
              + ","
              + flight.getDestination()
              + "\n";
    }
    returnString +=
        String.format("%.2f", cost)
            + "\n"
            + String.format("%02d", hours)
            + ":"
            + String.format("%02d", minutes);
    return returnString;
  }