Beispiel #1
0
        // calculate dynamically
        public void CalculateFlightDetails()
        {
            CostOfFlight         = Passengers.Count * FlightRoute.BaseCost;
            ProfitFromFlight     = Passengers.Sum(x => x.GetPrice(FlightRoute.BasePrice, FlightRoute.LoyaltyPointsGained));
            TotalExpectedBaggage = Passengers.Sum(x => x.AllowedBags);

            TotalLoyaltyPointsRedeemed = Passengers.OfType <LoyaltyPassenger>().Count(x => x.UsePoints)
                                         * Convert.ToInt32(Math.Ceiling(FlightRoute.BasePrice));

            TotalLoyaltyPointsAccrued = Passengers.OfType <LoyaltyPassenger>().Count(x => x.UsePoints == false)
                                        * FlightRoute.LoyaltyPointsGained;
        }
Beispiel #2
0
        /// <summary>
        /// Generates infomration about flight passengers
        /// </summary>
        /// <param name="result"><c>StringBuilder</c> with text to be displayed</param>
        private void AddPassengersDetails(ref StringBuilder result)
        {
            result.Append("Total passengers: ");
            result.Append(Passengers.Count);

            AddNewLine(ref result);
            AddIndentation(ref result);

            result.Append("General sales: ");
            result.Append(Passengers.OfType <General>().Count());

            AddNewLine(ref result);
            AddIndentation(ref result);

            result.Append("Loyalty member sales: ");
            result.Append(Passengers.OfType <Loyalty>().Count());

            AddNewLine(ref result);
            AddIndentation(ref result);

            result.Append("Airline employee comps: ");
            result.Append(Passengers.OfType <Airline>().Count());

            AddNewLine(ref result);
            AddIndentation(ref result);

            result.Append("Discounted sales: ");
            result.Append(Passengers.OfType <Discounted>().Count());

            AddVerticalWhiteSpace(ref result);
            result.Append("Total expected baggage: ");

            int baggageCount = 0;

            foreach (var passenger in Passengers)
            {
                baggageCount += passenger.AllowedBags;
            }

            result.Append(baggageCount);
        }
Beispiel #3
0
        /// <summary>
        /// Generates the full details of the current scheduled flight.
        /// </summary>
        /// <returns><c>string</c> representation of flight information</returns>
        /// <exception cref="ArgumentNullException">Thrown if a correct cast of RuleSet cannot be compoleted</exception>
        public string GetSummary()
        {
            foreach (var passenger in Passengers.OfType <Loyalty>())
            {
                if (passenger.IsUsingLoyaltyPoints)
                {
                    CalculateLoyaltyRedeemed(passenger);
                }
                else
                {
                    CalculateLoyaltyAccrued(passenger);
                }
            }

            CalculateRevenue();
            CalculateCosts();

            if (RuleSet is RelaxedRuleSet relaxedRuleSet)
            {
                relaxedRuleSet.MinPercentage         = FlightRoute.MinimumTakeOffPercentage;
                relaxedRuleSet.PassengerCount        = Passengers.Count;
                relaxedRuleSet.AirlinePassengerCount = Passengers.OfType <Airline>().Count();
                relaxedRuleSet.Profit    = CalculateProfit();
                relaxedRuleSet.SeatCount = Aircraft.NumberOfSeats;
                return(BuildSummaryString(relaxedRuleSet));
            }
            else if (RuleSet is DefaultRuleSet defaultRuleSet)
            {
                defaultRuleSet.MinPercentage  = FlightRoute.MinimumTakeOffPercentage;
                defaultRuleSet.PassengerCount = Passengers.Count;
                defaultRuleSet.Profit         = CalculateProfit();
                defaultRuleSet.SeatCount      = Aircraft.NumberOfSeats;
                return(BuildSummaryString(defaultRuleSet));
            }
            else
            {
                throw new ArgumentNullException("RuleSet", "RuleSet is not set to a known type.");
            }
        }