public Car CarCreate(string model, Engine engine, Cargo cargo, List <Tire> tires)
 {
     return(new Car(model, engine, cargo, tires));
 }
        private Car CreateCar(string model, Engine engine, Cargo cargo, List <Tire> tires)
        {
            Car car = new Car(model, engine, cargo, tires.ToArray());

            return(car);
        }
예제 #3
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]);
                KeyValuePair tire1         = KeyValuePair.Create(tire1Pressure, tire1Age);

                double       tire2Pressure = double.Parse(parameters[7]);
                int          tire2age      = int.Parse(parameters[8]);
                KeyValuePair tire2         = KeyValuePair.Create(tire2Pressure, tire2Age);

                double       tire3Pressure = double.Parse(parameters[9]);
                int          tire3age      = int.Parse(parameters[10]);
                KeyValuePair tire3         = KeyValuePair.Create(tire3Pressure, tire3Age);

                double       tire4Pressure = double.Parse(parameters[11]);
                int          tire4age      = int.Parse(parameters[12]);
                KeyValuePair tire4         = KeyValuePair.Create(tire4Pressure, tire4Age);

                KeyValuePair <double, int>[] tires = new KeyValuePair <double, int>[]
                {
                    tire1,
                    tire2,
                    tire3,
                    tire4
                };

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

            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));
            }
        }
        private Cargo CreateCargo(int weight, string type)
        {
            Cargo cargo = new Cargo(weight, type);

            return(cargo);
        }
예제 #5
0
        public static void Main()
        {
            int numberCars = int.Parse(Console.ReadLine());

            var listCars = new List <Car>();

            for (int i = 0; i < numberCars; i++)
            {
                string[] info = Console.ReadLine().Split();

                string model = info[0];

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

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

                double tire1Pressure = double.Parse(info[5]);
                int    tire1Age      = int.Parse(info[6]);
                double tire2Pressure = double.Parse(info[7]);
                int    tire2Age      = int.Parse(info[8]);
                double tire3Pressure = double.Parse(info[9]);
                int    tire3Age      = int.Parse(info[10]);
                double tire4Pressure = double.Parse(info[11]);
                int    tire4Age      = int.Parse(info[12]);

                var engine  = new Engine(engineSpeed, enginePower);
                var cargo   = new Cargo(cargoWeight, cargoType);
                var tireSet = new TireSet(tire1Pressure, tire1Age
                                          , tire2Pressure, tire2Age
                                          , tire3Pressure, tire3Age
                                          , tire4Pressure, tire4Age);

                var car = new Car(model, engine, cargo, tireSet);

                listCars.Add(car);
            }

            string command = Console.ReadLine();

            var result = new List <string>();

            foreach (var car in listCars)
            {
                if (command == "fragile" &&
                    car.Cargo.CargoType == "fragile" &&
                    car.TireSet.LittlePressureTire())
                {
                    result.Add(car.Model);
                }
                else if (command == "flamable" &&
                         car.Cargo.CargoType == "flamable" &&
                         car.Engine.EnginePower > 250)
                {
                    result.Add(car.Model);
                }
            }

            Console.WriteLine(string.Join(Environment.NewLine, result));
        }
예제 #6
0
        public void Run()
        {
            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];

                Tire[] tire1 = new Tire[4];

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

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

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

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


                Engine engine1 = new Engine(engineSpeed, enginePower);
                Cargo  cargo1  = new Cargo(cargoWeight, cargoType);
                cars.Add(new Car(model, engine1, cargo1, tire1));
            }
            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));
            }
        }
예제 #7
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);

                var secondParams = parameters.Skip(5).ToArray();

                Tire[] tires = new Tire[4];

                int counter = 0;
                for (int j = 0; j < secondParams.Length; j += 2)
                {
                    double currentTirePressure = double.Parse(secondParams[j]);
                    int    currentTireAge      = int.Parse(secondParams[j + 1]);

                    Tire currentTire = new Tire(currentTirePressure, currentTireAge);

                    tires[counter] = currentTire;
                    counter++;
                }

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



            string command = Console.ReadLine();

            if (command == "fragile")
            {
                List <string> fragile = cars
                                        .Where(c => c.Cargo.CargoType == "fragile" && c.Tires.Any(y => y.TirePressure < 1))
                                        .Select(c => c.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));
            }
        }
예제 #8
0
 private Car CreateCar(string model, Engine engine, Cargo cargo, Tire[] tires)
 {
     return(new Car(model, engine, cargo, tires));
 }