Beispiel #1
0
        public string AddRacer(string type, string username, string carVIN)
        {
            IRacer currentRaces = null;
            ICar   currentCar   = cars.FindBy(carVIN);

            if (currentCar == null)
            {
                throw new ArgumentException("Car cannot be found!");
            }
            if (type == "ProfessionalRacer")
            {
                currentRaces = new ProfessionalRacer(username, currentCar);
                racers.Add(currentRaces);
                return($"Successfully added racer {username}.");
            }
            else if (type == "StreetRacer")
            {
                currentRaces = new StreetRacer(username, currentCar);
                racers.Add(currentRaces);
                return($"Successfully added racer {username}.");
            }
            else
            {
                throw new ArgumentException("Invalid racer type!");
            }
        }
Beispiel #2
0
        public string AddRacer(string type, string username, string carVIN)
        {
            Racer racer = default;
            ICar  car   = cars.FindBy(carVIN);

            if (car == null)
            {
                throw new ArgumentException(ExceptionMessages.CarCannotBeFound);
            }

            if (type == nameof(ProfessionalRacer))
            {
                racer = new ProfessionalRacer(username, car);
            }
            else if (type == nameof(StreetRacer))
            {
                racer = new StreetRacer(username, car);
            }
            else
            {
                throw new ArgumentException(ExceptionMessages.InvalidRacerType);
            }

            racers.Add(racer);

            return(string.Format(OutputMessages.SuccessfullyAddedRacer, username));
        }
Beispiel #3
0
        public string AddRacer(string type, string username, string carVIN)
        {
            ICar car = cars.FindBy(carVIN);

            if (car is null)
            {
                throw new ArgumentException(ExceptionMessages.CarCannotBeFound);
            }

            IRacer racer;

            switch (type)
            {
            case "ProfessionalRacer":
                racer = new ProfessionalRacer(username, car);
                break;

            case "StreetRacer":
                racer = new StreetRacer(username, car);
                break;

            default:
                throw new ArgumentException(ExceptionMessages.InvalidRacerType);
            }

            racers.Add(racer);
            return(string.Format(OutputMessages.SuccessfullyAddedRacer, username));
        }