Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            CarFactory factory = new CarFactory();

            factory.Cars.Add(new Car {
                Id = 0, Make = "Holden", Model = "Commadore SV6", Colour = "Red"
            });
            factory.Cars.Add(new Car {
                Id = 1, Make = "Mercedes", Model = "SLA250", Colour = "Grey"
            });
            factory.Cars.Add(new Car {
                Id = 2, Make = "Holden", Model = "Commadore SV6", Colour = "Black"
            });
            factory.Cars.Add(new Car {
                Id = 3, Make = "Nissan", Model = "Juke", Colour = "Yellow"
            });
            factory.Cars.Add(new Car {
                Id = 4, Make = "Nissan", Model = "Leaf", Colour = "White"
            });
            factory.Cars.Add(new Car {
                Id = 5, Make = "Nissan", Model = "Leaf", Colour = "Black"
            });
            factory.Cars.Add(new Car {
                Id = 6, Make = "Nissan", Model = "Juke", Colour = "White"
            });
            factory.PrintCars();
            factory.Cars = factory.FilterByMake("Mercedes");
            factory.PrintCars();
        }
Ejemplo n.º 2
0
        public static List <CarFactory> Read(StreamReader sr)
        {
            List <CarFactory> cf         = new List <CarFactory>();
            CarFactory        newFactory = null;// = new CarFactory();
            string            line;

            while ((line = sr.ReadLine()) != null)
            {
                if (line == "#")
                {
                    if (newFactory != null)
                    {
                        cf.Add(newFactory);
                    }
                    newFactory      = new CarFactory();
                    newFactory.Name = sr.ReadLine();
                    continue;
                }
                try
                {
                    Car newCar = Car.Parse(line);
                    newFactory.Cars.Add(newCar);
                }
                catch (Exception error)
                {
                    Console.WriteLine("[CarFactory]: {0}", error.Message);
                    Console.WriteLine("Line: {0}", line);
                    continue;
                }
            }
            return(cf);
        }
        static void Main(string[] args)
        {
            Console.WriteLine("Hello Clarice!");
            CarFactory car = new CarFactory();

            string color    = car.GetColor();
            int    hp       = car.HorsePower();
            string features = car.Extras();

            Console.WriteLine();

            Console.WriteLine($"The car you have built is {color}, has {hp} horsepower, and comes with {features}");
        }
Ejemplo n.º 4
0
        static void Main(string[] args)
        {
            string  model            = string.Empty;
            string  color            = string.Empty;
            decimal price            = 0;
            decimal safetyRating     = 0;
            string  navigationSystem = string.Empty;
            string  bluetoothSupport = string.Empty;

            Console.WriteLine("Type 1 to create Camry, type 2 to create Accord");
            string result = Console.ReadLine();

            if (result.Equals("1", StringComparison.OrdinalIgnoreCase))
            {
                Camry newCamry = null;
                model = "Camry";
                Console.WriteLine("Enter color");
                color = Console.ReadLine();
                Console.WriteLine("Enter price");
                result = Console.ReadLine();
                decimal.TryParse(result, out price);
                Console.WriteLine("Enter safety rating");
                result = Console.ReadLine();
                decimal.TryParse(result, out safetyRating);
                Console.WriteLine("Enter navigation system, for example, GPS");
                navigationSystem = Console.ReadLine();
                newCamry         = (Camry)CarFactory.CreateCar(model, color, price, safetyRating, navigationSystem, string.Empty);

                Console.WriteLine($"New car was:\n Model: {newCamry.Model}\n NavigationSystem: {newCamry.NavigationSystem}\n Navigation system: {newCamry.NavigationSystem} \n Price: {newCamry.Price}\n Safety Rating {newCamry.SafetyRating}\n\n");
            }
            else if (result.Equals("2", StringComparison.OrdinalIgnoreCase))
            {
                Accord newAccord = null;
                model = "Accord";
                Console.WriteLine("Enter color");
                color = Console.ReadLine();
                Console.WriteLine("Enter price");
                result = Console.ReadLine();
                decimal.TryParse(result, out price);
                Console.WriteLine("Enter safety rating");
                result = Console.ReadLine();
                decimal.TryParse(result, out safetyRating);
                Console.WriteLine("Enter bluetooth support, for example, Y/N");
                bluetoothSupport = Console.ReadLine();
                newAccord        = (Accord)CarFactory.CreateCar(model, color, price, safetyRating, string.Empty, bluetoothSupport);
                Console.WriteLine($"New car was:\n Model: {newAccord.Model}\n Support bluetooth: {newAccord.BluetoothSupport}\n Price: {newAccord.Price}\n Safety Rating {newAccord.SafetyRating}\n\n");
            }

            Console.WriteLine("Enter any key to exit");
            Console.ReadKey();
        }
Ejemplo n.º 5
0
        static void Main(string[] args)
        {
            try
            {
                var cfList = CarFactory.Read(new System.IO.StreamReader("../../CarFactories.txt"));
                Console.WriteLine("Factory's car ordered by enbgine volume");
                foreach (var item in cfList)
                {
                    var cars = item.Cars.OrderBy(s => s.EngineVolume);
                    Console.WriteLine("\t{0}", item.Name);
                    foreach (var c in cars)
                    {
                        Console.WriteLine("\t\t{0}", c);
                    }
                }

                Console.WriteLine();
                Console.WriteLine();

                int lowerBound = 3;
                int upperBound = 5;
                Dictionary <CarFactory, int> carsCount = new Dictionary <CarFactory, int>();
                Console.WriteLine("Cars between {0} and {1} price", lowerBound, upperBound);
                foreach (var item in cfList)
                {
                    carsCount.Add(item, item.Cars.Count(s => lowerBound <= s.Price && s.Price <= upperBound));
                    Console.WriteLine("{0}\t-\t{1}", carsCount.Last().Key.Name, carsCount.Last().Value);
                }
                Console.WriteLine();
                Console.WriteLine();
                Console.WriteLine("Atuomatic vechile");

                var automatic =
                    (from item in cfList
                     where item.Cars.Any(s => (s is Vechile) && (s as Vechile).Automatic)
                     orderby item.Name ascending
                     select item.Name);
                foreach (var item in automatic)
                {
                    Console.WriteLine(item);
                }

                Console.WriteLine();
                Console.WriteLine();
                Console.WriteLine("Remove factories which produces more trucks");

                cfList =
                    (from item in cfList
                     where item.Cars.Count(s => s is Truck) <= item.Cars.Count(s => s is Vechile)
                     select item).ToList();

                foreach (var item in cfList)
                {
                    Console.WriteLine(item.Name);
                }
            }
            catch (Exception error)
            {
                Console.WriteLine("Fatal error ocurred: {0}", error.Message);
            }
            Console.ReadKey();
        }