示例#1
0
 /// <summary>
 /// Add a limousine to the administration
 /// </summary>
 /// <param name="sedan">The limousine to be added to the administration</param>
 public void Add(Limousine limousine)
 {
     if (limousine != null)
     {
         limousines.Add(limousine);
     }
 }
示例#2
0
        /// <summary>
        /// Rent a car
        /// </summary>
        /// <param name="licencePlate">The licence plate of the car to rent</param>
        /// <param name="rentalDate">The start date for the rental</param>
        /// <returns>true if the car was available for renting, false otherwise.</returns>
        public bool RentCar(string licencePlate, SimpleDate rentalDate)
        {
            // Try to find the car with the given licence plate. Is it a Sedan?
            Sedan foundSedan = null;

            foreach (Sedan sedan in sedans)
            {
                if (sedan.LicencePlate == licencePlate)
                {
                    foundSedan = sedan;
                    break;
                }
            }

            // Was a sedan with the given licene plate found? Then try to rent it.
            if (foundSedan != null)
            {
                return(foundSedan.Rent(rentalDate));
            }

            // No car found yet with the given licence plate.
            // Try to find the car with the given licence plate. Is it a Limousine?
            Limousine foundLimousine = null;

            foreach (Limousine limousine in limousines)
            {
                if (limousine.LicencePlate == licencePlate)
                {
                    foundLimousine = limousine;
                    break;
                }
            }

            // Was a limousine with the given licene plate found? Then try to rent it.
            if (foundLimousine != null)
            {
                return(foundLimousine.Rent(rentalDate));
            }

            // No car found yet with the given licence plate.
            // Try to find the car with the given licence plate. Is it a Truck?
            Truck foundTruck = null;

            foreach (Truck truck in trucks)
            {
                if (truck.LicencePlate == licencePlate)
                {
                    foundTruck = truck;
                    break;
                }
            }

            // Was a truck with the given licene plate found? Then try to rent it.
            if (foundTruck != null)
            {
                return(foundTruck.Rent(rentalDate));
            }

            return(false); // No Sedan nor Limousine nor Truck was found with the given licence plate.
        }
        /// <summary>
        /// Adds a limousine to the administration
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void addLimousineButton_Click(object sender, EventArgs e)
        {
            string    licencePlate = licencePlateTextBox.Text;
            bool      hasMiniBar   = miniBarComboBox.Text == "Yes";
            Limousine limousine    = new Limousine(manufacturerTextBox.Text, modelTextBox.Text,
                                                   licencePlate, hasMiniBar);

            administration.Add(limousine);
            UpdateAvailableCarListAndRentedCarLists();
        }