예제 #1
0
        /**
         * @param drivingLicense
         * @param typeOfCar
         * @return
         *  method determines whether the person is eligible to rent a car of the specified type and,
         *  if there is a car available, issues and associates that car with the driving license
         */
        public String IssueCar(DrivingLicense drivingLicense, String typeOfCar)
        {
            Calendar    cal   = CultureInfo.InvariantCulture.Calendar;
            DateTime    myDT  = new DateTime();
            int         year  = 2019;
            int         age   = int.Parse(drivingLicense.GetDateOfBirth().ToString().Substring(6, 4));
            int         issue = int.Parse(drivingLicense.GetDateOfIssue().ToString().Substring(6, 4));
            Boolean     valid = drivingLicense.IsLicenseValid();
            List <ICar> car   = drivingLicense.CarAssociated();

            //if the type of car is of type small
            if (typeOfCar == "small" || typeOfCar == "Small")
            {
                //if the driving license is valid, is over 21 years old and has held the license for a year
                if (valid == true && year - age >= 21 && year - issue >= 1)
                {
                    //method call to find a free small car
                    int i = FindFreeSmallCar();
                    //if size of list is less than 1
                    if (car.Count < MAX_NUMBER_OF_RENTED_CARS)
                    {
                        //add a small car to the list and set the car as rented
                        car.Add(smallCars[i]);
                        smallCars[i].SetRented(true);
                    }
                }
            }
            //if the type of car is of type large
            else if (typeOfCar == "large" || typeOfCar == "Large")
            {
                //if the driving license is valid, is over 25 years old and has held the license for 5 years
                if (valid == true && year - age >= 25 && year - issue >= 5)
                {
                    //method call to find a free large car
                    int i = FindFreeLargeCar();
                    //if size of list is less than 1
                    if (car.Count < MAX_NUMBER_OF_RENTED_CARS)
                    {
                        //add a small car to the list and set the car as rented
                        car.Add(largeCars[i]);
                        smallCars[i].SetRented(true);
                    }
                }
            }
            else
            {
                //if conditions for rental are not met then print statement
                return("Car cannot be issued.");
            }

            return("Car can be issued.");
        }
예제 #2
0
        /**
         * @param drivingLicense
         * @return
         * method disassociates the car currently rented with the driving license and returns fuel to fill the tank
         */
        public int TerminateRental(DrivingLicense drivingLicense)
        {
            List <ICar> car = drivingLicense.CarAssociated();
            int         i;

            //loops through maximum number of rented cars; 1
            for (i = 0; i < MAX_NUMBER_OF_RENTED_CARS; i++)
            {
                //if a car is there, break
                if (car != null)
                {
                    break;
                }
            }

            //change cars status to not rented and remove it from the driving license
            car[i].SetRented(false);
            int fuelConsumed = car[i].Capacity() - car[i].GetFuelInTank();

            car.Remove(car[i]);

            //return fuel required to fill the tank
            return(fuelConsumed);
        }
예제 #3
0
 /**
  * @param drivingLicense
  * @return
  *  method to return the car someone is currently renting
  */
 public List <ICar> GetCar(DrivingLicense drivingLicense)
 {
     //returns list of single car currently associated with the driving license
     return(drivingLicense.CarAssociated());
 }