示例#1
0
    public Flight(int id)  //creates flight using a reservation ID
    {
        try
        {
            this.resId          = id;
            this.planeName      = DBPlanes.getName(DBReservations.getPlane(resId));
            this.capacity       = DBPlanes.getCapacity(DBReservations.getPlane(resId));
            this.departureTime  = DBReservations.getDate(resId);
            this.destination    = DBDestinations.getLocation(DBReservations.getDestination(resId));
            this.travelDistance = DBDestinations.getDistanceFromLR(this.destination);
            this.flightSpeed    = DBPlanes.getSpeed(DBPlanes.getID(this.planeName));
            this.passengerCount = 0;
            this.travelTime     = ((this.travelDistance * 2) / this.flightSpeed) + 1; //Travel time to and from destination with 1 extra hour for refuling and acceleration/deceleration;


            List <string> flightResList = DBReservations.getReservationsByPlane(DBPlanes.getID(this.planeName));
            foreach (String s in flightResList) // "Out of all the reservations made for the plane that this Flight belongs to..." -ksm
            {
                int resNum = Convert.ToInt32(s);
                if (this.departureTime == DBReservations.getDate(resNum) && this.destination == DBDestinations.getLocation(DBReservations.getDestination(resNum)))
                {
                    this.passengerCount++; //"... Add 1 passenger for each reservation that matches this flight." -ksm
                }
            }
            this.seatsAvailable = this.capacity - this.passengerCount;

            this.returnTime = this.departureTime;
            TimeSpan time = TimeSpan.FromHours(travelTime);
            this.returnTime = this.returnTime + time;
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }
示例#2
0
    public Plane(int id)
    {
        try
        {
            this.id          = id;
            this.name        = DBPlanes.getName(id);
            this.mileRange   = DBPlanes.getRange(id);
            this.location    = DBPlanes.getLocation(id);
            this.cruiseSpeed = DBPlanes.getSpeed(id);

            List <string> resList = DBReservations.getReservationsByPlane(id);
            int           count   = 0;

            foreach (String res in resList)  // "For each reservation that this plane has create a flight based on reservation IDs" - ksm
            {
                flights[count] = new Flight(Convert.ToInt32(res));
                count++;
            }

            HashSet <Flight>         knownValues  = new HashSet <Flight>();
            Dictionary <int, Flight> uniqueValues = new Dictionary <int, Flight>();

            foreach (var pair in flights) // "Remove duplicate flights" -ksm
            {
                if (knownValues.Add(pair.Value))
                {
                    uniqueValues.Add(pair.Key, pair.Value);
                }
            }

            flights = uniqueValues;
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }