Exemplo n.º 1
0
        public VehicleModel(VehicleMake vehicleMake, string description, decimal currentYearPrice)
        {
            BaseConstructor(vehicleMake, description);

            if (VehiclePrices == null)
            {
                VehiclePrices = new List <VehiclePrice>();
            }

            var currentPrice = VehiclePrices.FirstOrDefault(p => p.Year == DateTime.Now.Year);

            if (currentPrice != null)
            {
                // update existing one
                currentPrice.Price = currentYearPrice;
            }
            else
            {
                // add current year price
                VehiclePrices.Add(new VehiclePrice
                {
                    Year  = DateTime.Now.Year,
                    Price = currentYearPrice
                });
            }
        }
Exemplo n.º 2
0
        private void BaseConstructor(VehicleMake vehicleMake, string description)
        {
            if (!string.IsNullOrEmpty(description))
            {
                this.Description = description;
            }
            else
            {
                throw new ArgumentNullException(nameof(Description));
            }

            this.VehicleMake = vehicleMake;
        }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            Console.WriteLine("Start");

            //implementation for g
            VehicleMake vehicleMake = new VehicleMake("Mercedes-Benz");


            //implementation for h
            VehicleModel vehicleModel = new VehicleModel(vehicleMake, "A180", 300000);

            Console.WriteLine("Complete");
            Console.ReadKey();
        }
Exemplo n.º 4
0
 public VehicleModel(VehicleMake vehicleMake, string description)
 {
     BaseConstructor(vehicleMake, description);
 }