示例#1
0
 /// <summary>
 /// Add a sedan to the administration
 /// </summary>
 /// <param name="sedan">The sedan to be added to the administration</param>
 public void Add(Sedan sedan)
 {
     if (sedan != null)
     {
         sedans.Add(sedan);
     }
 }
示例#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 sedan to the administration
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void addSedanButton_Click(object sender, EventArgs e)
        {
            string licencePlate = licencePlateTextBox.Text;
            bool   hasTowBar    = towBarComboBox.Text == "Yes";
            Sedan  sedan        = new Sedan(manufacturerTextBox.Text, modelTextBox.Text,
                                            licencePlate, hasTowBar);

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