static void Main(string[] args)
        {
            List <Car> cars  = new List <Car>();
            int        lines = int.Parse(Console.ReadLine());

            for (int i = 0; i < lines; i++)
            {
                string[] parameters    = Console.ReadLine().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                string   model         = parameters[0];
                int      engineSpeed   = int.Parse(parameters[1]);
                int      enginePower   = int.Parse(parameters[2]);
                int      cargoWeight   = int.Parse(parameters[3]);
                string   cargoType     = parameters[4];
                double   tire1Pressure = double.Parse(parameters[5]);
                int      tire1age      = int.Parse(parameters[6]);
                double   tire2Pressure = double.Parse(parameters[7]);
                int      tire2age      = int.Parse(parameters[8]);
                double   tire3Pressure = double.Parse(parameters[9]);
                int      tire3age      = int.Parse(parameters[10]);
                double   tire4Pressure = double.Parse(parameters[11]);
                int      tire4age      = int.Parse(parameters[12]);

                var engine = new Engine(engineSpeed, enginePower);
                var cargo  = new Cargo(cargoWeight, cargoType);
                var tire1  = new Tire(tire1Pressure, tire1age);
                var tire2  = new Tire(tire2Pressure, tire2age);
                var tire3  = new Tire(tire3Pressure, tire3age);
                var tire4  = new Tire(tire4Pressure, tire4age);
                cars.Add(new Car(model, engine, cargo, tire1, tire2, tire3, tire4));
            }

            string command = Console.ReadLine();

            if (command == "fragile")
            {
                List <string> fragile = cars
                                        .Where(x => x.Cargo.cargoType == "fragile" && x.Tire1.Pressure < 1 || x.Tire2.Pressure < 1 || x.Tire3.Pressure < 1 ||
                                               x.Tire4.Pressure < 1)
                                        .Select(x => x.Model)
                                        .ToList();

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

                Console.WriteLine(string.Join(Environment.NewLine, flamable));
            }
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            List <Car> cars  = new List <Car>();
            int        lines = int.Parse(Console.ReadLine());

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

                int     engineSpeed = int.Parse(parameters[1]);
                int     enginePower = int.Parse(parameters[2]);
                IEngine engine      = new Engine(engineSpeed, enginePower);

                int    cargoWeight = int.Parse(parameters[3]);
                string cargoType   = parameters[4];
                ICargo cargo       = new Cargo(cargoWeight, cargoType);

                ITire[] tires = new Tire[4];
                int     j     = 0;
                for (int z = 5; z < 13; z++)
                {
                    double tirePressure = double.Parse(parameters[z]);
                    z++;
                    int   tireAge = int.Parse(parameters[z]);
                    ITire tire    = new Tire(tirePressure, tireAge);
                    tires[j] = tire;
                    j++;
                }
                cars.Add(new Car(model, engine, cargo, tires));
            }

            string command = Console.ReadLine();

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

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

                Console.WriteLine(string.Join(Environment.NewLine, flamable));
            }
        }
Beispiel #3
0
        private static List <Tire> CreateTires(string[] parameters)
        {
            List <Tire> tires = new List <Tire>();

            for (int j = 0; j <= 6; j += 2)
            {
                double tirePressure = double.Parse(parameters[5 + j]);
                int    tireAge      = int.Parse(parameters[5 + j + 1]);
                Tire   tire         = new Tire(tirePressure, tireAge);
                tires.Add(tire);
            }

            return(tires);
        }
Beispiel #4
0
        public static void Run()
        {
            int lines = int.Parse(Console.ReadLine());

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

                int    engineSpeed = int.Parse(parameters[1]);
                int    enginePower = int.Parse(parameters[2]);
                Engine engine      = new Engine(engineSpeed, enginePower);

                int    cargoWeight = int.Parse(parameters[3]);
                string cargoType   = parameters[4];
                Cargo  cargo       = new Cargo(cargoWeight, cargoType);

                Tire[] tires = new Tire[(parameters.Length - 5) / 2];
                int    index = 5;
                for (int j = 0; j < tires.Length; j++)
                {
                    double pressure = double.Parse(parameters[index]);
                    index++;
                    int age = int.Parse(parameters[index]);
                    index++;
                    tires[j] = new Tire(age, pressure);
                }
                Car car = new Car(model, engine, cargo, tires);
                cars.Add(car);
            }

            string        command    = Console.ReadLine();
            List <string> neededCars = new List <string>();

            if (command == "fragile")
            {
                neededCars = cars.Where(x => x.Cargo.Type == "fragile" && x.Tires.Any(y => y.Pressure < 1))
                             .Select(x => x.Model)
                             .ToList();
            }
            else
            {
                neededCars = cars
                             .Where(x => x.Cargo.Type == "flamable" && x.Engine.Power > 250)
                             .Select(x => x.Model)
                             .ToList();
            }
            Console.WriteLine(string.Join(Environment.NewLine, neededCars));
        }
Beispiel #5
0
        static void Main(string[] args)
        {
            List <Car> cars  = new List <Car>();
            int        lines = int.Parse(Console.ReadLine());

            for (int i = 0; i < lines; i++)
            {
                string[] parameters = Console.ReadLine().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                string   model      = parameters[0];
                //
                int    engineSpeed = int.Parse(parameters[1]);
                int    enginePower = int.Parse(parameters[2]);
                Engine engine      = new Engine(engineSpeed, enginePower);
                //
                int    cargoWeight = int.Parse(parameters[3]);
                string cargoType   = parameters[4];
                Cargo  cargo       = new Cargo(cargoWeight, cargoType);
                //
                double      tire1Pressure = double.Parse(parameters[5]);
                int         tire1age      = int.Parse(parameters[6]);
                Tire        tire1         = new Tire(tire1Pressure, tire1age);
                double      tire2Pressure = double.Parse(parameters[7]);
                int         tire2age      = int.Parse(parameters[8]);
                Tire        tire2         = new Tire(tire2Pressure, tire2age);
                double      tire3Pressure = double.Parse(parameters[9]);
                int         tire3age      = int.Parse(parameters[10]);
                Tire        tire3         = new Tire(tire3Pressure, tire3age);
                double      tire4Pressure = double.Parse(parameters[11]);
                int         tire4age      = int.Parse(parameters[12]);
                Tire        tire4         = new Tire(tire4Pressure, tire4age);
                List <Tire> list          = new List <Tire>();
                list.Add(tire1);
                list.Add(tire2);
                list.Add(tire3);
                list.Add(tire4);
                //
                cars.Add(new Car(model, engine, cargo, list));
            }
            string command = Console.ReadLine();

            if (command == "fragile")
            {
                cars.Where(x => x.cargo.Type == "fragile").Where(y => y.tire.Any(z => z.Pessure < 1)).Select(x => x.model).ToList().ForEach(x => Console.WriteLine(x));
            }
            else if (command == "flamable")
            {
                cars.Where(x => x.cargo.Type == command).Where(y => y.engine.Power > 250).Select(x => x.model).ToList().ForEach(x => Console.WriteLine(x));
            }
        }
        public List <Tire> CreateTiresCollection(List <string> tiresParameters)
        {
            var tires = new List <Tire>();

            for (var i = 1; i < tiresParameters.Count; i += 2)
            {
                var tirePressure = double.Parse(tiresParameters[i - 1]);
                var tireAge      = int.Parse(tiresParameters[i]);

                var tire = new Tire(tirePressure, tireAge);
                tires.Add(tire);
            }

            return(tires);
        }
Beispiel #7
0
        public Car(string model, int engineSpeed, int enginePower,
                   int cargoWeight, string cargoType, double tire1Pressure,
                   int tire1Age, double tire2Pressure, int tire2Age,
                   double tire3Pressure, int tire3age, double tire4Pressure, int tire4age)
        {
            Model  = model;
            Engine = new Engine(engineSpeed, enginePower);
            Cargo  = new Cargo(cargoWeight, cargoType);
            Tires  = new Tire[4];

            Tires[0] = new Tire(tire1Pressure, tire1Age);
            Tires[1] = new Tire(tire2Pressure, tire2Age);
            Tires[2] = new Tire(tire3Pressure, tire3age);
            Tires[3] = new Tire(tire4Pressure, tire4age);
        }
        private List <Tire> SetTires(string[] tireData)
        {
            var tiresList = new List <Tire>();

            for (int i = 0; i < tireData.Length; i += 2)
            {
                double tirePressure = double.Parse(tireData[i]);
                int    tireAge      = int.Parse(tireData[i + 1]);

                var newTire = new Tire(tirePressure, tireAge);
                tiresList.Add(newTire);
            }

            return(tiresList);
        }
Beispiel #9
0
        public Car(string model, int engineSpeed, int enginePower, int cargoWeight, string cargoType, double tire1Pressure, int tire1Age, double tire2Pressure, int tire2Age, double tire3Pressure, int tire3age, double tire4Pressure, int tire4age)
        {
            Model  = model;
            Engine = new Engine(engineSpeed, enginePower);
            Cargo  = new Cargo(cargoWeight, cargoType);
            Tire tire1 = new Tire(tire1Pressure, tire1Age);
            Tire tire2 = new Tire(tire2Pressure, tire2Age);
            Tire tire3 = new Tire(tire3Pressure, tire3age);
            Tire tire4 = new Tire(tire4Pressure, tire4age);

            Tires.Add(tire1);
            Tires.Add(tire2);
            Tires.Add(tire3);
            Tires.Add(tire4);
        }
Beispiel #10
0
        private Tire[] GetTires(string[] parameters)
        {
            Tire[] tires     = new Tire[4];
            int    tireIndex = 0;

            for (int j = 5; j <= 12; j += 2)
            {
                double currentTirePressure = double.Parse(parameters[j]);
                int    currentTireAge      = int.Parse(parameters[j + 1]);
                Tire   currentTire         = tireFactory.Create(currentTirePressure, currentTireAge);
                tires[tireIndex] = currentTire;
                tireIndex++;
            }

            return(tires);
        }
Beispiel #11
0
        public Car(string model, int engineSpeed, int enginePower, int cargoWeight, string cargoType, double tire1Pressure, int tire1Age, double tire2Pressure, int tire2Age, double tire3Pressure, int tire3Age, double tire4Pressure, int tire4Age)
        {
            this.model  = model;
            this.engine = new Engine(engineSpeed, enginePower);
            this.cargo  = new Cargo(cargoWeight, cargoType);
            this.tires  = new List <Tire>();
            var tire1 = new Tire(tire1Pressure, tire1Age);
            var tire2 = new Tire(tire2Pressure, tire2Age);
            var tire3 = new Tire(tire3Pressure, tire3Age);
            var tire4 = new Tire(tire4Pressure, tire4Age);

            tires.Add(tire1);
            tires.Add(tire2);
            tires.Add(tire3);
            tires.Add(tire4);
        }
Beispiel #12
0
        public Car(string model, Engine engine, Cargo cargo, Tire tire1, Tire tire2, Tire tire3, Tire tire4)
        {
            this.Model = model;

            this.Cargo = cargo;

            this.Engine = engine;

            this.Tire1 = tire1;

            this.Tire2 = tire2;

            this.Tire3 = tire3;

            this.Tire4 = tire4;
        }
Beispiel #13
0
        static void Main(string[] args)
        {
            List <Car> cars       = new List <Car>();
            const int  TIRE_COUNT = 4;

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

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

                string model = parameters[0];

                Engine engine = new Engine(int.Parse(parameters[1]), int.Parse(parameters[2]));

                Cargo cargo = new Cargo(int.Parse(parameters[3]), parameters[4]);

                Tire[] tires      = new Tire[TIRE_COUNT];
                int    tireNumber = 0;

                for (int j = 5; j < 12; j += 2)
                {
                    Tire tire = new Tire(double.Parse(parameters[j]), int.Parse(parameters[j + 1]));

                    tires[tireNumber] = tire;

                    tireNumber++;
                }

                cars.Add(new Car(model, engine, cargo, tires));
            }

            List <string> carsModelsToPrint = new List <string>();

            string command = Console.ReadLine();

            if (command == "fragile")
            {
                carsModelsToPrint = SelectFragile(cars);
            }
            else if (command == "flamable")
            {
                carsModelsToPrint = SelectFlamable(cars);
            }

            Console.WriteLine(string.Join(Environment.NewLine, carsModelsToPrint));
        }
Beispiel #14
0
        public static void Main(string[] args)
        {
            List <Car> cars  = new List <Car>();
            int        lines = int.Parse(Console.ReadLine());

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

                int    engineSpeed = int.Parse(parameters[1]);
                int    enginePower = int.Parse(parameters[2]);
                Engine engine      = new Engine(engineSpeed, enginePower);

                int    cargoWeight = int.Parse(parameters[3]);
                string cargoType   = parameters[4];
                Cargo  cargo       = new Cargo(cargoWeight, cargoType);

                double tire1Pressure = double.Parse(parameters[5]);
                int    tire1age      = int.Parse(parameters[6]);
                double tire2Pressure = double.Parse(parameters[7]);
                int    tire2age      = int.Parse(parameters[8]);
                double tire3Pressure = double.Parse(parameters[9]);
                int    tire3age      = int.Parse(parameters[10]);
                double tire4Pressure = double.Parse(parameters[11]);
                int    tire4age      = int.Parse(parameters[12]);
                Tire   tire          = new Tire(tire1Pressure, tire1age, tire2Pressure, tire2age, tire3Pressure, tire3age, tire4Pressure, tire4age);

                cars.Add(new Car(model, engine, cargo, tire));
            }

            string command = Console.ReadLine();

            Predicate <Car> filter;

            if (command == "fragile")
            {
                filter = x => x.Cargo.CargoType == "fragile" && x.Tire.Tires.Any(y => y.Key < 1);
            }

            else
            {
                filter = x => x.Cargo.CargoType == "flamable" && x.Engine.EnginePower > 250;
            }

            Console.WriteLine(string.Join(Environment.NewLine, cars.FindAll(filter).Select(x => x.Model)));
        }
Beispiel #15
0
        private Tire[] GetTires(List <string> tireParameters)
        {
            Tire[] tires = new Tire[tireCount];

            int tireIndex = 0;

            for (int j = 0; j <= 7; j += 2)
            {
                double tirePressure = double.Parse(tireParameters[j]);
                int    tireAge      = int.Parse(tireParameters[j + 1]);
                Tire   tire         = new Tire(tirePressure, tireAge);
                tires[tireIndex] = tire;

                tireIndex++;
            }
            return(tires);
        }
Beispiel #16
0
        static void Main(string[] args)
        {
            List <Car> cars  = new List <Car>();
            int        lines = int.Parse(Console.ReadLine());

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

                string model  = parameters[0];
                Engine engine = new Engine(int.Parse(parameters[1]), int.Parse(parameters[2]));
                Cargo  cargo  = new Cargo(int.Parse(parameters[3]), parameters[4]);

                Tire[] tires = new Tire[]
                {
                    new Tire(double.Parse(parameters[5]), int.Parse(parameters[6])),
                    new Tire(double.Parse(parameters[7]), int.Parse(parameters[8])),
                    new Tire(double.Parse(parameters[9]), int.Parse(parameters[10])),
                    new Tire(double.Parse(parameters[11]), int.Parse(parameters[12])),
                };

                cars.Add(new Car(model, engine, cargo, tires));
            }

            string command = Console.ReadLine();

            if (command == "fragile")
            {
                List <string> fragile = cars
                                        .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 = cars
                                         .Where(x => x.Cargo.Type == "flamable" && x.Engine.Power > 250)
                                         .Select(x => x.Model)
                                         .ToList();

                Console.WriteLine(string.Join(Environment.NewLine, flamable));
            }
        }
        public Car(string model, int engineSpeed, int enginePower, int cargoWeight, string cargoType, double tire1Pressure, int tire1Age, double tire2Pressure, int tire2Age, double tire3Pressure, int tire3Age, double tire4Pressure, int tire4Age)
        {
            this.model       = model;
            this.engineSpeed = engineSpeed;
            this.enginePower = enginePower;
            this.cargoWeight = cargoWeight;
            this.cargoType   = cargoType;

            Tire t1 = new Tire(tire1Pressure, tire1Age);
            Tire t2 = new Tire(tire2Pressure, tire2Age);
            Tire t3 = new Tire(tire3Pressure, tire3Age);
            Tire t4 = new Tire(tire4Pressure, tire4Age);

            this.tireList = new List <Tire>();
            this.tireList.Add(t1);
            this.tireList.Add(t2);
            this.tireList.Add(t3);
            this.tireList.Add(t4);
        }
Beispiel #18
0
        private static void AddCar(List <Car> cars, int lines)
        {
            for (int i = 0; i < lines; i++)
            {
                string[] parameters = Console.ReadLine().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                string   model      = parameters[0];

                int    engineSpeed = int.Parse(parameters[1]);
                int    enginePower = int.Parse(parameters[2]);
                Engine engine      = new Engine(engineSpeed, enginePower);

                int    cargoWeight = int.Parse(parameters[3]);
                string cargoType   = parameters[4];
                Cargo  cargo       = new Cargo(cargoWeight, cargoType);


                double tire1Pressure = double.Parse(parameters[5]);
                int    tire1age      = int.Parse(parameters[6]);
                Tire   tire1         = new Tire(tire1Pressure, tire1age);

                double tire2Pressure = double.Parse(parameters[7]);
                int    tire2age      = int.Parse(parameters[8]);
                Tire   tire2         = new Tire(tire2Pressure, tire2age);

                double tire3Pressure = double.Parse(parameters[9]);
                int    tire3age      = int.Parse(parameters[10]);
                Tire   tire3         = new Tire(tire3Pressure, tire3age);

                double tire4Pressure = double.Parse(parameters[11]);
                int    tire4age      = int.Parse(parameters[12]);
                Tire   tire4         = new Tire(tire4Pressure, tire4age);

                List <Tire> tires = new List <Tire>();
                tires.Add(tire1);
                tires.Add(tire2);
                tires.Add(tire3);
                tires.Add(tire4);

                Car car = new Car(model, engine, cargo, tires);
                cars.Add(car);
            }
        }
Beispiel #19
0
        private Tire[] GetTires(List <string> tireParameters)
        {
            Tire[] tires = new Tire[tireCount];

            int tireIndex = 0;

            for (int j = 0; j < 8; j += 2)
            {
                double pressure = double.Parse(tireParameters[j]);
                int    age      = int.Parse(tireParameters[j + 1]);

                Tire tire = tireFactory.Create(pressure, age);

                tires[tireIndex] = tire;

                tireIndex++;
            }

            return(tires);
        }
Beispiel #20
0
        static void Main(string[] args)
        {
            List <Car> cars  = new List <Car>();
            int        lines = int.Parse(Console.ReadLine());

            for (int i = 0; i < lines; i++)
            {
                string[] parameters = Console.ReadLine().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                string   model      = parameters[0];
                var      engine     = new Engine(int.Parse(parameters[1]), int.Parse(parameters[2]));
                var      cargo      = new Cargo(int.Parse(parameters[3]), parameters[4]);
                var      tire1      = new Tire(double.Parse(parameters[5]), int.Parse(parameters[6]));
                var      tire2      = new Tire(double.Parse(parameters[7]), int.Parse(parameters[8]));
                var      tire3      = new Tire(double.Parse(parameters[9]), int.Parse(parameters[10]));
                var      tire4      = new Tire(double.Parse(parameters[11]), int.Parse(parameters[12]));

                cars.Add(new Car(model, engine.Speed, engine.Power, cargo.Weight, cargo.Type, tire1.Pressure, tire1.Age,
                                 tire2.Pressure, tire2.Age, tire3.Pressure, tire3.Age, tire4.Pressure, tire4.Age));
            }

            string command = Console.ReadLine();

            if (command == "fragile")
            {
                List <string> fragile = cars
                                        .Where(x => x.cargoType == "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.cargoType == "flamable" && x.enginePower > 250)
                                         .Select(x => x.model)
                                         .ToList();

                Console.WriteLine(string.Join(Environment.NewLine, flamable));
            }
        }
Beispiel #21
0
        private static Car CreateCar()
        {
            string[] parameters = Console.ReadLine().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            string   model      = parameters[0];

            int engineSpeed = int.Parse(parameters[1]);
            int enginePower = int.Parse(parameters[2]);

            Engine engine = new Engine(engineSpeed, enginePower);

            int    cargoWeight = int.Parse(parameters[3]);
            string cargoType   = parameters[4];


            Cargo cargo = new Cargo(cargoWeight, Enum.Parse <CargoType>(cargoType));


            double tire1Pressure = double.Parse(parameters[5]);
            int    tire1age      = int.Parse(parameters[6]);
            Tire   tire1         = new Tire(tire1age, tire1Pressure);

            double tire2Pressure = double.Parse(parameters[7]);
            int    tire2age      = int.Parse(parameters[8]);
            Tire   tire2         = new Tire(tire2age, tire2Pressure);

            double tire3Pressure = double.Parse(parameters[9]);
            int    tire3age      = int.Parse(parameters[10]);
            Tire   tire3         = new Tire(tire3age, tire3Pressure);

            double tire4Pressure = double.Parse(parameters[11]);
            int    tire4age      = int.Parse(parameters[12]);
            Tire   tire4         = new Tire(tire4age, tire4Pressure);

            List <Tire> tires = new List <Tire> {
                tire1, tire2, tire3, tire4
            };

            Car car = new Car(model, engine, cargo, tires);

            return(car);
        }
Beispiel #22
0
        private static Car CreateCar(string[] inputLine)
        {
            string model       = inputLine[0];
            int    engineSpeed = int.Parse(inputLine[1]);
            int    enginePower = int.Parse(inputLine[2]);
            int    cargoWeight = int.Parse(inputLine[3]);
            string cargoType   = inputLine[4];

            Engine      engine = new Engine(engineSpeed, enginePower);
            Cargo       cargo  = new Cargo(cargoWeight, cargoType);
            List <Tire> tires  = new List <Tire>();

            for (int j = 5; j < inputLine.Length; j += 2)
            {
                Tire tire = new Tire(double.Parse(inputLine[j]), int.Parse(inputLine[j + 1]));
                tires.Add(tire);
            }

            Car tempCar = new Car(model, engine, cargo, tires);

            return(tempCar);
        }
        public static void Main()
        {
            List <Car> cars = new List <Car>();

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

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

                Engine engine = new Engine(int.Parse(parameters[1]), int.Parse(parameters[2]));
                Cargo  cargo  = new Cargo(int.Parse(parameters[3]), parameters[4]);
                Tire[] tires  = new Tire[4]
                {
                    new Tire(double.Parse(parameters[5]), int.Parse(parameters[6])),
                    new Tire(double.Parse(parameters[7]), int.Parse(parameters[8])),
                    new Tire(double.Parse(parameters[9]), int.Parse(parameters[10])),
                    new Tire(double.Parse(parameters[11]), int.Parse(parameters[12]))
                };

                cars.Add(new Car(model, engine, cargo, tires));
            }

            string command = Console.ReadLine();

            if (command == "fragile")
            {
                cars.Where(c => c.Cargo.Type == "fragile" && c.Tires.Any(t => t.Pressure < 1))
                .ToList()
                .ForEach(c => Console.WriteLine(c.Model));
            }
            else
            {
                cars.Where(c => c.Cargo.Type == "flamable" && c.Engine.Power > 250)
                .ToList()
                .ForEach(c => Console.WriteLine(c.Model));
            }
        }
Beispiel #24
0
        private void ParseInput(int lines)
        {
            for (int i = 0; i < lines; i++)
            {
                string[] parameters = Console.ReadLine()
                                      .Split(" ", StringSplitOptions.RemoveEmptyEntries)
                                      .ToArray();

                string model = parameters[0];

                int engineSpeed = int.Parse(parameters[1]);
                int enginePower = int.Parse(parameters[2]);

                int    cargoWeight = int.Parse(parameters[3]);
                string cargoType   = parameters[4];

                double tire1Pressure = double.Parse(parameters[5]);
                int    tire1age      = int.Parse(parameters[6]);
                double tire2Pressure = double.Parse(parameters[7]);
                int    tire2age      = int.Parse(parameters[8]);
                double tire3Pressure = double.Parse(parameters[9]);
                int    tire3age      = int.Parse(parameters[10]);
                double tire4Pressure = double.Parse(parameters[11]);
                int    tire4age      = int.Parse(parameters[12]);

                Engine engine = this.CreateEngine(engineSpeed, enginePower);
                Cargo  cargo  = this.CreateCargo(cargoWeight, cargoType);

                Tire tire1 = this.CreateTire(tire1age, tire1Pressure);
                Tire tire2 = this.CreateTire(tire2age, tire2Pressure);
                Tire tire3 = this.CreateTire(tire3age, tire3Pressure);
                Tire tire4 = this.CreateTire(tire4age, tire4Pressure);

                Tire[] tires = new Tire[] { tire1, tire2, tire3, tire4 };

                Car car = this.CreateCar(model, engine, cargo, tires);
                this.cars.Add(car);
            }
        }
Beispiel #25
0
        public void Add(string[] parameters)
        {
            var model       = parameters[0];
            var engineSpeed = int.Parse(parameters[1]);
            var enginePower = int.Parse(parameters[2]);

            var engine = new Engine(engineSpeed, enginePower);

            var cargoWeight = int.Parse(parameters[3]);
            var cargoType   = parameters[4];

            var cargo = new Cargo(cargoWeight, cargoType);

            var tires = new Tire[TireCount]
            {
                new Tire(double.Parse(parameters[5]), int.Parse(parameters[6])),
                new Tire(double.Parse(parameters[7]), int.Parse(parameters[8])),
                new Tire(double.Parse(parameters[9]), int.Parse(parameters[10])),
                new Tire(double.Parse(parameters[11]), int.Parse(parameters[12]))
            };

            this.cars.Add(new Car(model, engine, cargo, tires));
        }
        public void Add(string[] paramaeters)
        {
            int numberOfCars = int.Parse(Console.ReadLine());

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

                string model = carParameters[0];

                int    engineSpeed = int.Parse(carParameters[1]);
                int    enginePower = int.Parse(carParameters[2]);
                int    cargoWeight = int.Parse(carParameters[3]);
                string cargoType   = carParameters[4];

                Engine engine = new Engine(engineSpeed, enginePower);
                Cargo  cargo  = new Cargo(cargoWeight, cargoType);
                Tire[] tires  = new Tire[4];

                int tireIndex = 0;

                for (int j = 5; j < 12; j++)
                {
                    double tirePressure = double.Parse(carParameters[j]);
                    int    tireAge      = int.Parse(carParameters[j]);

                    Tire tire = new Tire(tirePressure, tireAge);

                    tires[tireIndex] = tire;
                    tireIndex++;
                }

                Car car = new Car(model, engine, cargo, tires);
                cars.Add(car);
            }
        }
Beispiel #27
0
        private void GenerateCar(List <Car> cars, string[] parameters)
        {
            Tire[] tires = new Tire[4];

            string model = parameters[0];

            int    engineSpeed = int.Parse(parameters[1]);
            int    enginePower = int.Parse(parameters[2]);
            Engine engine      = new Engine(engineSpeed, enginePower);

            int    cargoWeight = int.Parse(parameters[3]);
            string cargoType   = parameters[4];
            Cargo  cargo       = new Cargo(cargoWeight, cargoType);

            double firstTirePressure = double.Parse(parameters[5]);
            int    firstTireAge      = int.Parse(parameters[6]);

            tires[0] = new Tire(firstTireAge, firstTirePressure);

            double secondTirePressure = double.Parse(parameters[7]);
            int    secondTireAge      = int.Parse(parameters[8]);

            tires[1] = new Tire(secondTireAge, secondTirePressure);

            double ThirdTirePressure = double.Parse(parameters[9]);
            int    thirdTireAge      = int.Parse(parameters[10]);

            tires[2] = new Tire(thirdTireAge, ThirdTirePressure);

            double fourthTirePressure = double.Parse(parameters[11]);
            int    fourthTireAge      = int.Parse(parameters[12]);

            tires[3] = new Tire(fourthTireAge, fourthTirePressure);

            cars.Add(new Car(model, engine, cargo, tires));
        }
Beispiel #28
0
        public static void Main(string[] args)
        {
            List <Car> cars = new List <Car>();

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

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

                string model = parameters[0];

                int engineSpeed = int.Parse(parameters[1]);
                int enginePower = int.Parse(parameters[2]);

                Engine engine = new Engine(engineSpeed, enginePower);

                int    cargoWeight = int.Parse(parameters[3]);
                string cargoType   = parameters[4];

                Cargo cargo = new Cargo(cargoType, cargoWeight);

                List <Tire> tires = new List <Tire>();

                for (int j = 0; j < 8; j += 2)
                {
                    double tirePressure = double.Parse(parameters[5 + j]);
                    int    tireAge      = int.Parse(parameters[6 + j]);
                    Tire   tire         = new Tire(tireAge, tirePressure);
                    tires.Add(tire);
                }

                Car car = new Car(model, engine, cargo, tires);
                cars.Add(car);
            }

            List <string> resultModels = new List <string>();

            string command = Console.ReadLine();

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


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

                Console.WriteLine(string.Join(Environment.NewLine, resultModels));
            }
        }
Beispiel #29
0
 public Car(string model, Engine engine, Cargo cargo, Tire tire1, Tire tire2, Tire tire3, Tire tire4)
 {
     this.model  = model;
     this.engine = engine;
     this.cargo  = cargo;
     this.tires  = new Tire[] { tire1, tire2, tire3, tire4 };
 }
Beispiel #30
0
        static void Main(string[] args)
        {
            List <Car> cars  = new List <Car>();
            int        lines = int.Parse(Console.ReadLine());

            for (int i = 0; i < lines; i++)
            {
                Tire[] tires = new Tire[4];

                string[] parameters = Console.ReadLine().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

                string model = parameters[0];

                int engineSpeed = int.Parse(parameters[1]);
                int enginePower = int.Parse(parameters[2]);

                Engine engine = new Engine(engineSpeed, enginePower);

                int    cargoWeight = int.Parse(parameters[3]);
                string cargoType   = parameters[4];

                Cargo cargo = new Cargo(cargoWeight, cargoType);

                double firstTirePressure = double.Parse(parameters[5]);
                int    firstTireAge      = int.Parse(parameters[6]);

                tires[0] = new Tire(firstTireAge, firstTirePressure);

                double secondTirePressure = double.Parse(parameters[7]);
                int    secondTireAge      = int.Parse(parameters[8]);

                tires[1] = new Tire(secondTireAge, secondTirePressure);

                double thirdTirePressure = double.Parse(parameters[9]);
                int    thirdTireAge      = int.Parse(parameters[10]);

                tires[2] = new Tire(thirdTireAge, thirdTirePressure);

                double forthTirePressure = double.Parse(parameters[11]);
                int    forthTireAge      = int.Parse(parameters[12]);

                tires[3] = new Tire(forthTireAge, forthTirePressure);

                cars.Add(new Car(model, cargo, engine, tires));
            }

            string command = Console.ReadLine();

            if (command == "fragile")
            {
                List <string> fragile = cars
                                        .Where(x => x.Cargo.CargoType == "fragile" && x.Tires.Any(y => y.TirePressure < 1))
                                        .Select(x => x.Model)
                                        .ToList();

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

                Console.WriteLine(string.Join(Environment.NewLine, flamable));
            }
        }