Esempio n. 1
0
        public string GetCars(string command, CarCatalog carCatalog)
        {
            StringBuilder sb = new StringBuilder();

            if (command == "fragile")
            {
                List <string> fragile = carCatalog.GetCars()
                                        .Where(x => x.Cargo.Type == "fragile" && x.Tires.Any(y => y.Pressure < 1))
                                        .Select(x => x.Model)
                                        .ToList();

                sb.AppendLine(string.Join(Environment.NewLine, fragile));
            }
            else
            {
                List <string> flamable = carCatalog.GetCars()
                                         .Where(x => x.Cargo.Type == "flamable" && x.Engine.Power > 250)
                                         .Select(x => x.Model)
                                         .ToList();

                sb.AppendLine(string.Join(Environment.NewLine, flamable));
            }

            return(sb.ToString().Trim());
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            int        lines      = int.Parse(Console.ReadLine());
            CarCatalog carCatalog = new CarCatalog();

            for (int i = 0; i < lines; i++)
            {
                string[] parameters = Console.ReadLine().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

                carCatalog.Add(parameters);
            }

            string command = Console.ReadLine();

            if (command == "fragile")
            {
                List <string> fragile = carCatalog.GetCars
                                        .Where(x => x.Cargo.Type == "fragile" && x.Tires.Any(y => y.Pressure < 1))
                                        .Select(x => x.Model)
                                        .ToList();

                Console.WriteLine(string.Join(Environment.NewLine, fragile));
            }
            else
            {
                List <string> flamable = carCatalog.GetCars
                                         .Where(x => x.Cargo.Type == "flamable" && x.Engine.Power > 250)
                                         .Select(x => x.Model)
                                         .ToList();

                Console.WriteLine(string.Join(Environment.NewLine, flamable));
            }
        }
Esempio n. 3
0
        public void Run()
        {
            var lines   = int.Parse(Console.ReadLine());
            var catalog = new CarCatalog();

            for (int i = 0; i < lines; i++)
            {
                var parameters = Console.ReadLine().Split(' ', StringSplitOptions.RemoveEmptyEntries);
                catalog.Add(parameters);
            }

            var command = Console.ReadLine();

            if (command == "fragile")
            {
                var fragile = catalog.GetAllCars()
                              .Where(x => x.Cargo.Type == "fragile" && x.Tires.Any(y => y.Pressure < 1))
                              .Select(x => x.Model)
                              .ToList();

                Console.WriteLine(string.Join(Environment.NewLine, fragile));
            }
            else
            {
                var flamable = catalog.GetAllCars()
                               .Where(x => x.Cargo.Type == "flamable" && x.Engine.Power > 250)
                               .Select(x => x.Model)
                               .ToList();

                Console.WriteLine(string.Join(Environment.NewLine, flamable));
            }
        }
Esempio n. 4
0
        public static void Main()
        {
            CarCatalog carCatalog = new CarCatalog();

            string command = Console.ReadLine();

            if (command == "fragile")
            {
                List <string> fragile = cars
                                        .Where(x => x.Cargo.Type == "fragile" && x.tires.Any(y => y.Key < 1))
                                        .Select(x => x.model)
                                        .ToList();

                Console.WriteLine(string.Join(Environment.NewLine, fragile));
            }
            else
            {
                List <string> flamable = cars
                                         .Where(x => x.Cargo.Type == "flamable" && x.Engine.Power > 250)
                                         .Select(x => x.Model)
                                         .ToList();

                Console.WriteLine(string.Join(Environment.NewLine, flamable));
            }
        }
Esempio n. 5
0
        public void Run()
        {
            CarFactory    carFactory    = new CarFactory();
            EngineFactory engineFactory = new EngineFactory();
            CargoFactory  cargoFactory  = new CargoFactory();
            TireFactory   tireFactory   = new TireFactory();

            CarCatalog carCatalog = new CarCatalog(carFactory, engineFactory, cargoFactory, tireFactory);

            int lines = int.Parse(Console.ReadLine());

            for (int i = 0; i < lines; i++)
            {
                string[] parameters = Console.ReadLine()
                                      ?.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

                carCatalog.Add(parameters);
            }

            string command = Console.ReadLine();

            switch (command)
            {
            case "fragile":
                List <string> fragile = carCatalog.GetCars()
                                        .Where(x => x.Cargo.Type == "fragile" && x.Tires.Any(y => y.Pressure < 1))
                                        .Select(x => x.Model)
                                        .ToList();

                PrintInfo(fragile);
                break;

            case "flamable":
                List <string> flamable = carCatalog.GetCars()
                                         .Where(x => x.Cargo.Type == "flamable" && x.Engine.Power > 250)
                                         .Select(x => x.Model)
                                         .ToList();

                PrintInfo(flamable);
                break;
            }
        }
Esempio n. 6
0
        public static void Main()
        {
            EngineFactory engineFactory = new EngineFactory();
            TireFactory   tireFactory   = new TireFactory();
            CargoFactory  cargoFactory  = new CargoFactory();
            CarCatalog    carCatalog    = new CarCatalog(engineFactory, tireFactory, cargoFactory);
            int           lines         = int.Parse(Console.ReadLine());

            for (int i = 0; i < lines; i++)
            {
                string[] parameters = Console.ReadLine().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                carCatalog.Add(parameters);
            }

            string command = Console.ReadLine();

            Filter filter = new Filter();

            Console.WriteLine(filter.GetCars(command, carCatalog));
        }
 public Runner(CarCatalog cars)
 {
     this.cars = cars;
 }